1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//! A module providing a Clear trait which signals metrics to clear their state
//! if applicable.

use std::sync::Arc;

/// The `Clear` trait is used to signal metrics to clear their state if
/// applicable
///
/// While it is recommended all metrics should implement `Clear`, for instance
/// to derive `Clear` on registries, some metrics may choose to do nothing. For
/// instance, Gauges would be left in an inconsistent state if they were altered
/// during clear.
pub trait Clear {
    /// Requests to clear self.
    fn clear(&self);
}

impl<T: Clear> Clear for Arc<T> {
    fn clear(&self) {
        (&**self).clear();
    }
}

impl<T: Clear> Clear for &T {
    fn clear(&self) {
        (*self).clear();
    }
}

/// The `Clearable` trait is used to provide metadata around some types that can
/// be cleared.
pub trait Clearable {
    /// Returns true if self has been cleared and not yet been written to since.
    fn is_cleared(&self) -> bool;
}