Skip to main content

ControlSpec

Enum ControlSpec 

Source
pub enum ControlSpec {
    Setpoint {
        setpoint: f32,
        hysteresis: f32,
        cooling: bool,
        safe_band: f32,
    },
    Level {
        empty: f32,
        warn_within: u32,
    },
    Surge {
        rising: bool,
        limit: f32,
    },
    Monitor,
    Custom {
        kind: String,
        params: Params,
    },
}
Expand description

How a profile turns each reading into control output and alerts.

This is the policy half of a profile’s manifest: the tunable rule a community can publish and share, with no code to write. Profile::controller assembles it into a live Controller. In a manifest it is tagged by kind, with the kind’s parameters beside it:

{ "kind": "setpoint", "setpoint": 5.0, "hysteresis": 0.5, "cooling": true, "safe_band": 3.0 }

A kind the library does not know is a Custom policy: it loads with every other field kept as its Params, and a PolicyRegistry resolves it to the code that decides it, so a manifest for a policy of your own reads exactly like one for a setpoint:

{ "kind": "frost_guard", "warn_below": 2.0 }

Variants§

§

Setpoint

Hold a reading near setpoint by switching an output on and off.

Fields

§setpoint: f32

The target reading, such as 5 C for a vaccine fridge.

§hysteresis: f32

Half the deadband width around the setpoint, which stops the output chattering at the threshold.

§cooling: bool

Whether the output cools (switches on above the band) or heats (switches on below it). An irrigation valve that adds water is a “heater”.

§safe_band: f32

How far the reading may stray from the setpoint before an Alert::OutOfRange fires.

§

Level

Watch a falling level and warn before it reaches empty.

Fields

§empty: f32

The level treated as empty, such as a dry tank.

§warn_within: u32

Warn once the level is estimated to reach empty within this many more samples.

§

Surge

Warn when a reading changes faster than limit per sample.

Fields

§rising: bool

Watch a rapid rise (true) or a rapid fall (false).

§limit: f32

The largest safe change per sample.

§

Monitor

Report readings only, with no control output and no alerts.

§

Custom

A policy the library does not ship, named by the manifest and decided by code a PolicyRegistry resolves the kind to.

Fields

§kind: String

The kind as the manifest names it, such as "frost_guard".

§params: Params

Every other field the manifest carried beside the kind.

Implementations§

Source§

impl ControlSpec

Source

pub const BUILT_IN: [&'static str; 4]

The kinds the library ships, as a manifest names them.

Source

pub fn kind(&self) -> &str

Returns the kind as a manifest names it.

§Returns

"setpoint", "level", "surge", "monitor", or a custom kind’s own name.

Source

pub fn custom(kind: impl Into<String>, params: Params) -> Result<Self>

Creates a policy of a kind the library does not ship, checked so it survives a trip through its manifest.

§Arguments
  • kind - the kind as the manifest will name it, such as "frost_guard".
  • params - every other field the policy needs.
§Returns

The custom policy.

§Errors

Returns Error::Codec if kind is empty or names a built-in kind, which a manifest would read back as that kind, or if params holds a field named kind, which the manifest keeps for the kind itself.

§Examples
use pamoja_profile::{ControlSpec, Params};

let guard = ControlSpec::custom("frost_guard", Params::new().with("warn_below", 2.0))?;
assert_eq!(guard.kind(), "frost_guard");
assert!(ControlSpec::custom("setpoint", Params::new()).is_err());

Trait Implementations§

Source§

impl Clone for ControlSpec

Source§

fn clone(&self) -> ControlSpec

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 ControlSpec

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ControlSpec

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for ControlSpec

Source§

fn eq(&self, other: &ControlSpec) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ControlSpec

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ControlSpec

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.