rust_hdl_core/
direction.rs

1use crate::atom::AtomKind;
2
3#[doc(hidden)]
4pub trait Direction: Clone {
5    const KIND: AtomKind;
6}
7
8/// This direction marker is used for a [Signal] that is
9/// an input with respect to a circuit.  That means
10/// that we do not expect to write to the input, but that
11/// the value will be set by external components to the
12/// circuit.
13/// ```rust
14/// use rust_hdl_core::prelude::*;
15///
16/// struct Foo {
17///     pub x: Signal<In, Bit>,     // <--- This is a single bit input
18///     pub y: Signal<In, Bits<8>>, // <--- This is a multi-bit input signal
19/// }
20/// ```
21#[derive(Default, Clone, Debug)]
22pub struct In {}
23
24/// This direction marker is used for a [Signal] that
25/// leaves a circuit as an output.  That means we expect this
26/// circuit to drive the signal using its internal logic.
27/// It is an error in RustHDL to leave an output undriven.
28#[derive(Default, Clone, Debug)]
29pub struct Out {}
30
31#[derive(Default, Clone, Debug)]
32pub struct Local {}
33
34#[derive(Default, Clone, Debug)]
35pub struct InOut {}
36
37impl Direction for In {
38    const KIND: AtomKind = AtomKind::InputParameter;
39}
40
41impl Direction for Out {
42    const KIND: AtomKind = AtomKind::OutputParameter;
43}
44
45impl Direction for Local {
46    const KIND: AtomKind = AtomKind::LocalSignal;
47}
48
49impl Direction for InOut {
50    const KIND: AtomKind = AtomKind::InOutParameter;
51}