metrix/instruments/switches/
mod.rs

1//! Switched have a boolean state that is changed by
2//! `Observation`s.
3//!
4//! Switches can be used to attach alerts.
5use std::borrow::Cow;
6
7mod flag;
8mod non_occurrence_indicator;
9mod occurrence_indicator;
10mod staircase_timer;
11
12pub use self::flag::Flag;
13pub use self::non_occurrence_indicator::NonOccurrenceIndicator;
14pub use self::occurrence_indicator::OccurrenceIndicator;
15pub use self::staircase_timer::StaircaseTimer;
16
17/// Describes how to change a name using the given `String` in the variant.
18#[derive(Debug, Clone)]
19pub enum NameAlternation {
20    /// Prefix the original name
21    Prefix(String),
22    /// Postfix the original name
23    Postfix(String),
24    /// Replace the original name
25    Rename(String),
26}
27
28impl NameAlternation {
29    fn adjust_name<'a>(&'a self, original: &str) -> Cow<'a, str> {
30        match self {
31            NameAlternation::Rename(s) => Cow::Borrowed(s),
32            NameAlternation::Prefix(s) => Cow::Owned(format!("{}{}", s, original)),
33            NameAlternation::Postfix(s) => Cow::Owned(format!("{}{}", original, s)),
34        }
35    }
36}