Skip to main content

Reading

Struct Reading 

Source
pub struct Reading {
    pub key: String,
    pub value: f32,
    pub unit: String,
    pub status: Status,
    pub band: Option<[f32; 2]>,
    pub viz: Option<String>,
    pub trend: Option<Trend>,
    pub state: Option<String>,
    pub actions: Option<Vec<String>>,
    pub stat: bool,
}
Expand description

A single measured value, named by a stable key and a canonical unit.

Fields§

§key: String

A stable, language-neutral element key, such as "soil_moisture".

§value: f32

The raw measured value, in the canonical unit.

§unit: String

The canonical unit name, such as "percent", "celsius", or "volt".

§status: Status

The health of this reading on its own.

§band: Option<[f32; 2]>

The safe band [low, high] in the same unit, drawn as the gauge’s safe zone.

§viz: Option<String>

An explicit visualization kind that overrides the page’s key/unit heuristic, such as "radial" or "bar". Set from a profile’s Viz with with_viz so a custom reading is drawn the way its profile intends; None lets the page pick from the key and unit.

§trend: Option<Trend>

Which way the reading is moving, if known.

§state: Option<String>

A discrete state code for a non-numeric reading, such as "state.open" for a valve or "pump.nominal" for a pump, which the page renders as a labelled chip. Numeric readings leave this None.

§actions: Option<Vec<String>>

The discrete actions this reading can be commanded to, such as ["open", "closed"] for a valve. Present only on a controllable actuator; a read-only sensor leaves this None, and the page shows control only when it is set.

§stat: bool

Whether this is a node or network stat (neighbours, hops, link or relay status, a tamper-log record count) rather than a measurement of the world. The page counts and renders stats apart from sensors. Defaults false.

Implementations§

Source§

impl Reading

Source

pub fn new(key: impl Into<String>, value: f32, unit: impl Into<String>) -> Self

Creates a reading in good standing with no band or trend.

§Arguments
  • key - the stable element key.
  • value - the raw measured value.
  • unit - the canonical unit name.
§Returns

A Status::Ok reading carrying just the value and unit.

Source

pub fn with_status(self, status: Status) -> Self

Sets the reading’s health.

§Arguments
  • status - the health to record.
§Returns

The reading, for chaining.

Source

pub fn with_band(self, low: f32, high: f32) -> Self

Sets the safe band drawn as the gauge’s safe zone.

§Arguments
  • low - the bottom of the safe band.
  • high - the top of the safe band.
§Returns

The reading, for chaining.

Source

pub fn with_viz(self, viz: Viz) -> Self

Pins the graphic this reading is drawn with, overriding the page’s heuristic.

Use this when a profile declares a custom element with Viz and you want the live reading drawn the same way, regardless of its key and unit.

§Arguments
  • viz - the graphic to draw the reading with.
§Returns

The reading, for chaining.

Source

pub fn with_trend(self, trend: Trend) -> Self

Sets the reading’s trend arrow.

§Arguments
  • trend - which way the reading is moving.
§Returns

The reading, for chaining.

Source

pub fn with_state(self, state: impl Into<String>) -> Self

Sets a discrete state code for a non-numeric reading, rendered as a chip.

§Arguments
  • state - the stable state code, such as "state.open".
§Returns

The reading, for chaining.

Source

pub fn with_actions( self, actions: impl IntoIterator<Item = impl Into<String>>, ) -> Self

Marks the reading as a controllable actuator with the given discrete actions.

§Arguments
  • actions - the action codes a client may command, such as ["open", "closed"].
§Returns

The reading, for chaining.

Source

pub fn as_stat(self) -> Self

Marks the reading as a node or network stat rather than a measurement, so the page counts and renders it apart from sensors.

§Returns

The reading, for chaining.

Trait Implementations§

Source§

impl Clone for Reading

Source§

fn clone(&self) -> Reading

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 Reading

Source§

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

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

impl<'de> Deserialize<'de> for Reading

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

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

impl PartialEq for Reading

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Reading

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

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

impl StructuralPartialEq for Reading

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> Same for T

Source§

type Output = T

Should always be Self
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.