Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug, Clone)]
- pub enum Output {
- True,
- False
- }
- impl Output {
- pub fn invert(&self) -> Output {
- match self {
- Output::True => Output::False,
- Output::False => Output::True
- }
- }
- }
- enum Node {
- Not(NotGate),
- Signal(SignalGate)
- }
- impl Node {
- fn get_output(&self) -> Output {
- match self {
- Node::Not(gate) => gate.get_output(),
- Node::Signal(gate) => gate.get_output()
- }
- }
- }
- struct NotGate {
- inputs: Vec<&Node>
- }
- struct SignalGate {
- signal: Output
- }
- trait NodeTrait {
- fn get_output(&self) -> Output;
- }
- impl NodeTrait for NotGate {
- fn get_output(&self) -> Output {
- self.inputs[0].get_output().invert()
- }
- }
- impl NodeTrait for SignalGate {
- fn get_output(&self) -> Output {
- self.signal.clone()
- }
- }
- fn main() {
- let x = Node::Not(NotGate {
- inputs: Vec::new()
- });
- let y = Node::Not(NotGate {
- inputs: vec![&x]
- });
- let z = Node
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement