Skip to main content

Part

Trait Part 

Source
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§

Source

fn drive(&self, pin: PinId) -> Drive

What this pin drives onto its net. HIGH_Z when the part only listens.

Source

fn set_pin(&mut self, pin: PinId, level: Level, now: Tick)

Called for every level change on a net this part is attached to.

Provided Methods§

Source

fn next_event(&self) -> Option<Tick>

Earliest tick at which this part wants Part::advance called.

Source

fn advance(&mut self, _now: Tick)

Source

fn state(&self) -> PartState

What a UI or a test can read back without knowing the part’s type.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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".

Implementors§