pub struct MetricWidget { /* private fields */ }Expand description
A single metric widget in the dashboard.
Implementations§
Source§impl MetricWidget
impl MetricWidget
Sourcepub fn counter(label: impl Into<String>, value: i64) -> Self
pub fn counter(label: impl Into<String>, value: i64) -> Self
Creates a counter widget.
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::counter("Requests", 42);
assert_eq!(widget.label(), "Requests");
assert_eq!(widget.display_value(), "42");Sourcepub fn gauge(label: impl Into<String>, value: u64, max: u64) -> Self
pub fn gauge(label: impl Into<String>, value: u64, max: u64) -> Self
Creates a gauge widget with a maximum value.
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::gauge("CPU %", 75, 100);
assert_eq!(widget.display_value(), "75/100");Sourcepub fn status(label: impl Into<String>, up: bool) -> Self
pub fn status(label: impl Into<String>, up: bool) -> Self
Creates a status indicator widget.
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::status("API", true);
assert_eq!(widget.label(), "API");
assert_eq!(widget.display_value(), "UP");Sourcepub fn text(label: impl Into<String>, text: impl Into<String>) -> Self
pub fn text(label: impl Into<String>, text: impl Into<String>) -> Self
Creates a text metric widget.
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::text("Version", "1.2.3");
assert_eq!(widget.label(), "Version");
assert_eq!(widget.display_value(), "1.2.3");Sourcepub fn with_max_history(self, max: usize) -> Self
pub fn with_max_history(self, max: usize) -> Self
Sets the maximum history length for sparkline display (builder pattern).
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::counter("Ops", 0).with_max_history(50);
assert_eq!(widget.history().len(), 0); // no values yetSourcepub fn label(&self) -> &str
pub fn label(&self) -> &str
Returns the label.
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::counter("Requests", 0);
assert_eq!(widget.label(), "Requests");Sourcepub fn kind(&self) -> &MetricKind
pub fn kind(&self) -> &MetricKind
Returns the metric kind.
§Example
use envision::component::{MetricWidget, MetricKind};
let widget = MetricWidget::status("DB", false);
assert!(matches!(widget.kind(), MetricKind::Status { up: false }));Sourcepub fn history(&self) -> &[u64]
pub fn history(&self) -> &[u64]
Returns the sparkline history.
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::counter("Ops", 0);
assert!(widget.history().is_empty());Sourcepub fn display_value(&self) -> String
pub fn display_value(&self) -> String
Returns the display value as a string.
§Example
use envision::component::MetricWidget;
assert_eq!(MetricWidget::counter("A", 42).display_value(), "42");
assert_eq!(MetricWidget::gauge("B", 75, 100).display_value(), "75/100");
assert_eq!(MetricWidget::status("C", true).display_value(), "UP");
assert_eq!(MetricWidget::status("D", false).display_value(), "DOWN");
assert_eq!(MetricWidget::text("E", "ok").display_value(), "ok");Sourcepub fn set_counter_value(&mut self, value: i64)
pub fn set_counter_value(&mut self, value: i64)
Sets the counter value.
§Example
use envision::component::MetricWidget;
let mut widget = MetricWidget::counter("Requests", 0);
widget.set_counter_value(100);
assert_eq!(widget.display_value(), "100");Sourcepub fn set_gauge_value(&mut self, value: u64)
pub fn set_gauge_value(&mut self, value: u64)
Sets the gauge value.
§Example
use envision::component::MetricWidget;
let mut widget = MetricWidget::gauge("Memory", 0, 1024);
widget.set_gauge_value(512);
assert_eq!(widget.display_value(), "512/1024");Sourcepub fn set_status(&mut self, up: bool)
pub fn set_status(&mut self, up: bool)
Sets the status.
§Example
use envision::component::MetricWidget;
let mut widget = MetricWidget::status("API", true);
widget.set_status(false);
assert_eq!(widget.display_value(), "DOWN");Sourcepub fn set_text(&mut self, text: impl Into<String>)
pub fn set_text(&mut self, text: impl Into<String>)
Sets the text value.
§Example
use envision::component::MetricWidget;
let mut widget = MetricWidget::text("Version", "1.0");
widget.set_text("2.0");
assert_eq!(widget.display_value(), "2.0");Sourcepub fn increment(&mut self, amount: i64)
pub fn increment(&mut self, amount: i64)
Increments a counter by the given amount.
§Example
use envision::component::MetricWidget;
let mut widget = MetricWidget::counter("Hits", 10);
widget.increment(5);
assert_eq!(widget.display_value(), "15");Sourcepub fn gauge_percentage(&self) -> Option<f64>
pub fn gauge_percentage(&self) -> Option<f64>
Returns the gauge fill percentage (0.0 to 1.0).
Returns None for non-gauge widgets.
§Example
use envision::component::MetricWidget;
let widget = MetricWidget::gauge("CPU", 75, 100);
assert_eq!(widget.gauge_percentage(), Some(0.75));
let counter = MetricWidget::counter("Ops", 10);
assert_eq!(counter.gauge_percentage(), None);Trait Implementations§
Source§impl Clone for MetricWidget
impl Clone for MetricWidget
Source§fn clone(&self) -> MetricWidget
fn clone(&self) -> MetricWidget
Returns a duplicate 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 MetricWidget
impl Debug for MetricWidget
Source§impl<'de> Deserialize<'de> for MetricWidget
impl<'de> Deserialize<'de> for MetricWidget
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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 MetricWidget
impl PartialEq for MetricWidget
Source§impl Serialize for MetricWidget
impl Serialize for MetricWidget
impl StructuralPartialEq for MetricWidget
Auto Trait Implementations§
impl Freeze for MetricWidget
impl RefUnwindSafe for MetricWidget
impl Send for MetricWidget
impl Sync for MetricWidget
impl Unpin for MetricWidget
impl UnsafeUnpin for MetricWidget
impl UnwindSafe for MetricWidget
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more