[][src]Struct metrix::snapshot::Snapshot

pub struct Snapshot {
    pub items: Vec<(String, ItemKind)>,
}

A Snapshot which contains measured values at a point in time.

Fields

items: Vec<(String, ItemKind)>

Methods

impl Snapshot[src]

pub fn push<K: Into<String>, V: Into<ItemKind>>(&mut self, k: K, v: V)[src]

pub fn find_with_separator(&self, path: &str, separator: char) -> FindItem[src]

Find an item on a path with a given a separator.

Same as find but with a configurable separator.

pub fn find(&self, path: &str) -> FindItem[src]

Find an item on a path with a / as a separator.

If the path is empty None is returned.

Since a Snapshot may contain multiple items with the same name only the first found will be returned.

If a prefix of a path leads to a value that value is returned and the rest of the path is discarded.

Empty segments of a path are ignored.

Example

use metrix::snapshot::*;
use metrix::snapshot::FindItem::*;

// a -> 23
// b -> c -> 42

let inner = ItemKind::Snapshot(Snapshot {
    items: vec![("c".to_string(), ItemKind::UInt(42))],
});

let snapshot = Snapshot {
    items: vec![
        ("a".to_string(), ItemKind::UInt(23)),
        ("b".to_string(), inner.clone()),
    ],
};

assert_eq!(snapshot.find("a"), Found(&ItemKind::UInt(23)));
assert_eq!(snapshot.find("a/x"), Found(&ItemKind::UInt(23)));
assert_eq!(snapshot.find("/a/x"), Found(&ItemKind::UInt(23)));

assert_eq!(snapshot.find("b"), Found(&inner));

assert_eq!(snapshot.find("b/c"), Found(&ItemKind::UInt(42)));
assert_eq!(snapshot.find("/b//c"), Found(&ItemKind::UInt(42)));

assert_eq!(snapshot.find("b/c/x"), Found(&ItemKind::UInt(42)));

assert_eq!(snapshot.find(""), NotFound);

assert_eq!(snapshot.find("/"), NotFound);

pub fn to_default_json(&self) -> String[src]

Output JSON with default settings.

pub fn to_json(&self, config: &JsonConfig) -> String[src]

Output JSON with the given settings.

Trait Implementations

impl Clone for Snapshot[src]

impl Debug for Snapshot[src]

impl Default for Snapshot[src]

impl From<Snapshot> for ItemKind[src]

impl PartialEq<Snapshot> for Snapshot[src]

impl StructuralPartialEq for Snapshot[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,