pub struct UsageMetric { /* private fields */ }Expand description
A single usage metric entry.
Represents a label-value pair with optional color and icon.
§Example
use envision::component::UsageMetric;
use ratatui::style::Color;
let metric = UsageMetric::new("CPU", "45%")
.with_color(Color::Green)
.with_icon("*");
assert_eq!(metric.label(), "CPU");
assert_eq!(metric.value(), "45%");
assert_eq!(metric.color(), Some(Color::Green));
assert_eq!(metric.icon(), Some("*"));Implementations§
Source§impl UsageMetric
impl UsageMetric
Sourcepub fn new(label: impl Into<String>, value: impl Into<String>) -> Self
pub fn new(label: impl Into<String>, value: impl Into<String>) -> Self
Creates a new usage metric with a label and value.
§Example
use envision::component::UsageMetric;
let metric = UsageMetric::new("CPU", "45%");
assert_eq!(metric.label(), "CPU");
assert_eq!(metric.value(), "45%");
assert_eq!(metric.color(), None);
assert_eq!(metric.icon(), None);Sourcepub fn with_color(self, color: Color) -> Self
pub fn with_color(self, color: Color) -> Self
Sets the color for the metric value.
§Example
use envision::component::UsageMetric;
use ratatui::style::Color;
let metric = UsageMetric::new("CPU", "45%").with_color(Color::Green);
assert_eq!(metric.color(), Some(Color::Green));Sourcepub fn with_icon(self, icon: impl Into<String>) -> Self
pub fn with_icon(self, icon: impl Into<String>) -> Self
Sets the icon prefix for the metric.
§Example
use envision::component::UsageMetric;
let metric = UsageMetric::new("CPU", "45%").with_icon("*");
assert_eq!(metric.icon(), Some("*"));Sourcepub fn set_label(&mut self, label: impl Into<String>)
pub fn set_label(&mut self, label: impl Into<String>)
Sets the metric label.
§Example
use envision::component::UsageMetric;
let mut metric = UsageMetric::new("CPU", "45%");
metric.set_label("Processor");
assert_eq!(metric.label(), "Processor");Sourcepub fn set_value(&mut self, value: impl Into<String>)
pub fn set_value(&mut self, value: impl Into<String>)
Sets the metric value.
§Example
use envision::component::UsageMetric;
let mut metric = UsageMetric::new("CPU", "45%");
metric.set_value("80%");
assert_eq!(metric.value(), "80%");Trait Implementations§
Source§impl Clone for UsageMetric
impl Clone for UsageMetric
Source§fn clone(&self) -> UsageMetric
fn clone(&self) -> UsageMetric
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 UsageMetric
impl Debug for UsageMetric
Source§impl<'de> Deserialize<'de> for UsageMetric
impl<'de> Deserialize<'de> for UsageMetric
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 UsageMetric
impl PartialEq for UsageMetric
Source§impl Serialize for UsageMetric
impl Serialize for UsageMetric
impl Eq for UsageMetric
impl StructuralPartialEq for UsageMetric
Auto Trait Implementations§
impl Freeze for UsageMetric
impl RefUnwindSafe for UsageMetric
impl Send for UsageMetric
impl Sync for UsageMetric
impl Unpin for UsageMetric
impl UnsafeUnpin for UsageMetric
impl UnwindSafe for UsageMetric
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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