Skip to main content

Variable

Struct Variable 

Source
pub struct Variable {
    pub id: VarId,
    pub subject: String,
    pub key: String,
    pub kind: VarKind,
    pub verb: String,
    pub span: Span,
    pub set: Option<String>,
    pub shows: Vec<(Option<String>, String)>,
}
Expand description

A state of the system: “the kettle is off | heating | dry”.

Fields§

§id: VarId§subject: String

As declared, e.g. “the kettle”.

§key: String

Normalised for matching, e.g. “kettle”.

§kind: VarKind§verb: String

The verb it was declared with, which steps about it read with: “is”, “are”, “has” (“the drawing has 0..100 shapes”) or “have”.

§span: Span§set: Option<String>

How docs tell the reader to change it, with {value} for the value (“open the dial to {value}”). Without it: “set the dial to 80 %”.

§shows: Vec<(Option<String>, String)>

What the reader sees, from Shows: lines: for one value (“dry”, “the display says DRY”, or “at least 99 %” for a number), or for any value with {value} in it (None, “the button reads UPLOAD {value}”).

Implementations§

Source§

impl Variable

Source

pub fn shown_shift(&self, shift: Shift) -> Option<String>

What the reader sees when it’s exactly one value, if a Shows: line says. What the reader sees when it changes by shift, if a Shows: line says: one keyed “goes up by 1”, “goes down by 10 m” or “stays the same”, as relative Thens write them.

Source

pub fn shown(&self, c: &Constraint) -> Option<String>

Source

pub fn full(&self) -> Constraint

The constraint that allows every value.

Source

pub fn value_index(&self, name: &str) -> Option<usize>

Source

pub fn witness(&self, c: &Constraint) -> Option<Value>

A concrete value inside c to drive the system with: the first allowed name, or the middle of a numeric range.

Source

pub fn admits(&self, c: &Constraint, v: &Value) -> bool

Does the observed value satisfy c? Numbers get a tolerance of a millionth of the state’s range, so a value that went through an f32 still reads as what it was set to.

Source

pub fn describe(&self, c: &Constraint) -> String

“the kettle is heating”, “the dial is above 55 %”.

Source

pub fn predicate(&self, c: &Constraint) -> String

“is heating”, “is not dry”, “is between 20 and 40 %” (“are …” for a plural subject).

Trait Implementations§

Source§

impl Clone for Variable

Source§

fn clone(&self) -> Variable

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Variable

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.