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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use decoder;
use crate*;
/// Returns the output of a [multiplexer](https://en.wikipedia.org/wiki/Multiplexer).
/// which selects one of the `inputs` by `address`.
/// If `inputs` is not big enough to cover the whole address space, it will get filled by [OFF].
///
/// # Example
/// ```
/// # use logicsim::{GateGraphBuilder,multiplexer,WordInput,ON,OFF};
/// # let mut g = GateGraphBuilder::new();
/// let address = WordInput::new(&mut g, 3, "address");
///
/// // Notice the carry and invert in bits are on.
/// let result = multiplexer(&mut g, &address.bits(), &[ON, OFF, OFF, ON], "mux");
/// let output = g.output1(result, "result");
///
/// let ig = &mut g.init();
/// ig.run_until_stable(2);
///
/// assert_eq!(output.b0(ig), true);
///
/// address.set_to(ig, 1);
/// ig.run_until_stable(2);
/// assert_eq!(output.b0(ig), false);
///
/// address.set_to(ig, 2);
/// ig.run_until_stable(2);
/// assert_eq!(output.b0(ig), false);
///
/// address.set_to(ig, 3);
/// ig.run_until_stable(2);
/// assert_eq!(output.b0(ig), true);
/// ```
///
/// # Panics
///
/// Will panic if not enough `address` bits are provided to address every `input`.