pub trait Part {
// Required methods
fn drive(&self, pin: PinId) -> Drive;
fn set_pin(&mut self, pin: PinId, level: Level, now: Tick);
// Provided methods
fn next_event(&self) -> Option<Tick> { ... }
fn advance(&mut self, _now: Tick) { ... }
fn state(&self) -> PartState { ... }
fn press(&mut self, _pressed: bool) -> bool { ... }
fn set_control(&mut self, _value: u16) -> bool { ... }
fn set_named_control(&mut self, _name: &str, _value: &str) -> bool { ... }
fn analog(&self, _pin: PinId) -> Option<f32> { ... }
fn current_limit(&self) -> Option<f32> { ... }
}Expand description
A schematic component. Parts never read MCU registers; they react to pin levels and to time, which is the same contract a real part has.
Pin ids are indices into the part’s own pin table, assigned once when the board is flattened, so a driver never has to match strings at run time.
Required Methods§
Provided Methods§
Sourcefn next_event(&self) -> Option<Tick>
fn next_event(&self) -> Option<Tick>
Earliest tick at which this part wants Part::advance called.
fn advance(&mut self, _now: Tick)
Sourcefn state(&self) -> PartState
fn state(&self) -> PartState
What a UI or a test can read back without knowing the part’s type.
Sourcefn press(&mut self, _pressed: bool) -> bool
fn press(&mut self, _pressed: bool) -> bool
Host interaction: a person pressed this part. Returns whether the part has such an input at all, so a UI can tell a button from an LED.
Sourcefn set_control(&mut self, _value: u16) -> bool
fn set_control(&mut self, _value: u16) -> bool
Host interaction: a person moved a continuous control, in permille (0 through 1000). Returns whether the part has such a control.
Sourcefn set_named_control(&mut self, _name: &str, _value: &str) -> bool
fn set_named_control(&mut self, _name: &str, _value: &str) -> bool
Host interaction by name, the way a test or a scenario says it: a
button’s pressed, a sensor’s temperature, a joystick’s x. The
value stays text because one name can be a percentage, a boolean or a
physical unit; the part decides how to read it. Returns whether the
part has that control.
Sourcefn analog(&self, _pin: PinId) -> Option<f32>
fn analog(&self, _pin: PinId) -> Option<f32>
The analog voltage in volts this pin holds, for parts that source one
(a potentiometer wiper, a sensor output). Digital parts return None
on every pin; a net with an analog source is still resolved as a
digital level for everything else on it.
Sourcefn current_limit(&self) -> Option<f32>
fn current_limit(&self) -> Option<f32>
The output current at which a regulated source stops holding its set
voltage and delivers this much instead, in amperes. None for a part
that does not limit: a battery, a rail, a plain source.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".