Skip to main content

ElementSpec

Struct ElementSpec 

pub struct ElementSpec {
    pub key: String,
    pub unit: String,
    pub label: String,
    pub labels: Option<BTreeMap<String, String>>,
    pub viz: Viz,
    pub band: Option<[f32; 2]>,
    pub stat: bool,
    pub scope: Scope,
    pub span: bool,
    pub value: Option<f32>,
    pub state: Option<String>,
}
Expand description

A custom sensor or node stat a profile contributes to the dashboard.

This is the unit of a Presentation: one element keyed by a stable, language- neutral key, drawn with a chosen Viz, scoped to the groups it belongs on, and labelled for people who do not read the key. The snapshot still carries the raw value under key; this names how to show it.

Fields§

§key: String

The stable, language-neutral element key, such as "water_turbidity".

§unit: String

The canonical unit name, such as "ntu", "ph", or "count".

§label: String

A human-readable fallback label, shown when no localized label is available.

§labels: Option<BTreeMap<String, String>>

Optional per-locale labels, keyed by locale tag ("en", "sw", …). A locale present here is shown in that locale; otherwise the page falls back to label.

§viz: Viz

The graphic this element is drawn with.

§band: Option<[f32; 2]>

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

§stat: bool

Whether this is a node or network stat rather than a measurement of the world. Stats are counted and rendered apart from sensors. Defaults false.

§scope: Scope

Which groups this element is offered on. Defaults to Scope::Always.

§span: bool

Whether the element’s tile spans two columns, for a wide graphic. Defaults false.

§value: Option<f32>

A starting numeric value for the add-sensor dialog, before a real sample arrives.

§state: Option<String>

A starting discrete state code, such as "state.closed", for a non-numeric element.

Implementations§

§

impl ElementSpec

pub fn new( key: impl Into<String>, unit: impl Into<String>, label: impl Into<String>, viz: Viz, ) -> ElementSpec

Declares a numeric element drawn with the given graphic.

§Arguments
  • key - the stable, language-neutral element key.
  • unit - the canonical unit name.
  • label - a human-readable fallback label.
  • viz - the graphic to draw it with.
§Returns

A measurement element offered on every group, with no band yet.

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

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

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

The element, for chaining.

pub fn on(self, scope: Scope) -> ElementSpec

Restricts the groups this element is offered on.

§Arguments
  • scope - the groups the add-sensor dialog offers this element on.
§Returns

The element, for chaining.

pub fn as_stat(self) -> ElementSpec

Marks the element as a node or network stat rather than a measurement.

§Returns

The element, for chaining.

pub fn with_value(self, value: f32) -> ElementSpec

Sets a starting value shown until the first real sample arrives.

§Arguments
  • value - the starting numeric value.
§Returns

The element, for chaining.

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

Sets a starting discrete state code for a non-numeric element.

§Arguments
  • state - the starting state code, such as "state.closed".
§Returns

The element, for chaining.

pub fn wide(self) -> ElementSpec

Spans the element’s tile across two columns, for a wide graphic.

§Returns

The element, for chaining.

pub fn with_locale_label( self, locale: impl Into<String>, label: impl Into<String>, ) -> ElementSpec

Adds a localized label for one locale.

§Arguments
  • locale - the locale tag, such as "sw".
  • label - the element’s label in that locale.
§Returns

The element, for chaining.

Trait Implementations§

§

impl Clone for ElementSpec

§

fn clone(&self) -> ElementSpec

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
§

impl Debug for ElementSpec

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for ElementSpec

§

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

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

impl PartialEq for ElementSpec

§

fn eq(&self, other: &ElementSpec) -> 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.
§

impl Serialize for ElementSpec

§

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

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

impl StructuralPartialEq for ElementSpec

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.