pub struct StatusValue { /* private fields */ }Expand description
A self-describing status leaf (Grand Unified Log Strategy).
Serialises to {"value":..,"type":..,"unit"?:..,"label"?:..,"hint"?:..} and
is detected downstream (FleetManager UI) by the presence of type; a leaf
without type renders as a plain value. Because it derives Serialize, a
StatusValue can be embedded directly in a serde_json::json! literal or a
StatusSource::get_status() result anywhere a scalar would go — no wrapper
needed. See docs/architecture/grand-unified-log-strategy.md.
use brinkhaustools::StatusValue;
let leaf = serde_json::json!({
"connected": StatusValue::boolean(true).label("status.foo.connected"),
"maxAge": StatusValue::duration(90, "days"),
});
assert_eq!(leaf["connected"]["type"], "bool");
assert_eq!(leaf["maxAge"]["unit"], "days");Implementations§
Source§impl StatusValue
impl StatusValue
Sourcepub fn enumeration(v: impl Into<String>) -> Self
pub fn enumeration(v: impl Into<String>) -> Self
Enumerated string (e.g. a state name).
Sourcepub fn duration(v: impl Into<Value>, unit: &str) -> Self
pub fn duration(v: impl Into<Value>, unit: &str) -> Self
Duration v in unit (e.g. "s", "ms", "days").
Sourcepub fn label(self, l: impl Into<String>) -> Self
pub fn label(self, l: impl Into<String>) -> Self
Attach an i18n label key (e.g. status.foo.connected).
Sourcepub fn hint(self, h: impl Into<String>) -> Self
pub fn hint(self, h: impl Into<String>) -> Self
Override the display hint (default derived from type).
Sourcepub fn into_value(self) -> Value
pub fn into_value(self) -> Value
Materialise as a serde_json::Value descriptor object.
Trait Implementations§
Source§impl Clone for StatusValue
impl Clone for StatusValue
Source§fn clone(&self) -> StatusValue
fn clone(&self) -> StatusValue
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for StatusValue
impl Debug for StatusValue
Source§impl From<StatusValue> for Value
impl From<StatusValue> for Value
Source§fn from(sv: StatusValue) -> Self
fn from(sv: StatusValue) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for StatusValue
impl RefUnwindSafe for StatusValue
impl Send for StatusValue
impl Sync for StatusValue
impl Unpin for StatusValue
impl UnwindSafe for StatusValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more