Struct metrics_util::Registry [−][src]
A high-performance metric registry.
Registry
provides the ability to maintain a central listing of metrics mapped by a given key.
In many cases, K
will be a composite key, where the fundamental Key
type from metrics
is
present, and differentiation is provided by storing the metric type alongside.
Metrics themselves are represented opaquely behind H
. In most cases, this would be a
thread-safe handle to the underlying metrics storage that the owner of the registry can use to
update the actual metric value(s) as needed. Handle
, from this crate, is a solid default
choice.
As well, handles have an associated generation counter which is incremented any time an entry is operated on. This generation is returned with the handle when querying the registry, and can be used in order to delete a handle from the registry, allowing callers to prune old/stale handles over time.
Registry
is optimized for reads.
Implementations
impl<K, H> Registry<K, H> where
K: Eq + Hash + Clone + 'static,
H: 'static,
[src]
K: Eq + Hash + Clone + 'static,
H: 'static,
pub fn new() -> Self
[src]
Creates a new Registry
.
pub fn op<I, O, V>(&self, key: K, op: O, init: I) -> V where
I: FnOnce() -> H,
O: FnOnce(&H) -> V,
[src]
I: FnOnce() -> H,
O: FnOnce(&H) -> V,
Perform an operation on a given key.
The op
function will be called for the handle under the given key
.
If the key
is not already mapped, the init
function will be
called, and the resulting handle will be stored in the registry.
pub fn delete(&self, key: &K, generation: Generation) -> bool
[src]
Deletes a handle from the registry.
The generation of a given key is passed along when querying the registry via
get_handles
. If the generation given here does not match the
current generation, then the handle will not be removed.
pub fn get_handles(&self) -> HashMap<K, (Generation, H)> where
H: Clone,
[src]
H: Clone,
Gets a map of all present handles, mapped by key.
Handles must implement Clone
. This map is a point-in-time snapshot of the registry.
pub fn collect<T>(&self) -> T where
H: Clone,
T: FromIterator<(K, (Generation, H))>,
[src]
H: Clone,
T: FromIterator<(K, (Generation, H))>,
Collects all present key and associated generation/handle pairs
into the provided type T
.
Handles must implement Clone
.
This collected result is a point-in-time snapshot of the registry.
pub fn map_collect<F, R, T>(&self, f: F) -> T where
F: for<'a> FnMut(&'a K, Generation, &'a H) -> R,
T: FromIterator<R>,
[src]
F: for<'a> FnMut(&'a K, Generation, &'a H) -> R,
T: FromIterator<R>,
Maps and then collects all present key and associated generation/handle
pairs into the provided type T
.
This map is appied over the values from a point-in-time snapshot of the registry.
Trait Implementations
impl<K: Debug, H: Debug> Debug for Registry<K, H> where
K: Eq + Hash + Clone + 'static,
H: 'static,
[src]
K: Eq + Hash + Clone + 'static,
H: 'static,
impl<K, H> Default for Registry<K, H> where
K: Eq + Hash + Clone + 'static,
H: 'static,
[src]
K: Eq + Hash + Clone + 'static,
H: 'static,
Auto Trait Implementations
impl<K, H> !RefUnwindSafe for Registry<K, H>
impl<K, H> Send for Registry<K, H> where
H: Send,
K: Send,
H: Send,
K: Send,
impl<K, H> Sync for Registry<K, H> where
H: Send + Sync,
K: Send + Sync,
H: Send + Sync,
K: Send + Sync,
impl<K, H> Unpin for Registry<K, H>
impl<K, H> UnwindSafe for Registry<K, H> where
H: UnwindSafe,
K: UnwindSafe,
H: UnwindSafe,
K: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,