summaryrefslogtreecommitdiff
path: root/src/pin.rs
blob: 2602d26fded71f7d42944bf03b8e335ae7a89206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::types::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PinType {
    Undetermined,
    ChipInput,
    GateInput,
    GateOutput,
    ChipOutput,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Pin {
    pub id: usize,
    pub kind: PinType,
    pub gate_id: usize,
    pub val: Option<PinValue>,
}

impl Pin {
    pub fn new(kind: PinType, gate_id: usize, val: PinValue) -> Self {
        static mut ID: usize = 0;
        unsafe {
            ID += 1;
            match kind {
                PinType::Undetermined => Pin {
                    id: ID,
                    gate_id,
                    kind,
                    val: None,
                },
                _ => Pin {
                    id: ID,
                    gate_id,
                    kind,
                    val: Some(val),
                },
            }
        }
    }
}