simple/simple.rs
1use safety_net::{Gate, Netlist};
2
3fn and_gate() -> Gate {
4 Gate::new_logical("AND".into(), vec!["A".into(), "B".into()], "Y".into())
5}
6
7fn main() {
8 let netlist = Netlist::new("example".to_string());
9
10 // Add the the two inputs
11 let a = netlist.insert_input("a".into());
12 let b = netlist.insert_input("b".into());
13
14 // Instantiate an AND gate
15 let instance = netlist
16 .insert_gate(and_gate(), "inst_0".into(), &[a, b])
17 .unwrap();
18
19 // Make this AND gate an output
20 instance.expose_with_name("y".into());
21
22 // Print the netlist
23 println!("{netlist}");
24}