Skip to main content

runnerd_core/api/
figure.rs

1//! A figure as every client shows it among others: its label, its value and what it is out of, worded here so the
2//! dashboard and the TUI show the same words. Clients lay figures out and never word them. Holds no state.
3
4/// One figure of a group: `Median a job` `120M`, or `Lookups hit, 7 days` `75%` `of 400`.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct LabelledFigure {
7    /// What it counts: `Median a job`.
8    pub label: String,
9    /// The figure: `120M`.
10    pub value: String,
11    /// What it is out of, where it says: `of 400`.
12    pub of: Option<String>,
13}
14
15impl LabelledFigure {
16    /// `value`, labelled `label`.
17    pub(crate) fn new(label: impl Into<String>, value: impl Into<String>) -> Self {
18        Self {
19            label: label.into(),
20            value: value.into(),
21            of: None,
22        }
23    }
24
25    /// It, out of `of`.
26    pub(crate) fn of(mut self, of: impl Into<String>) -> Self {
27        self.of = Some(of.into());
28        self
29    }
30}