log_types/
span.rs

1use log::kv::{Key, Source, ToKey, ToValue, Value, Visitor, Error};
2
3/// Delimit a span.
4///
5/// Spans delimit two arbitrary points in time. Usually a measurement between those two points
6/// points to something useful.
7///
8/// The key of this enum is serialized as `span_mark`, the value is either `start` or `end`.
9#[derive(Debug)]
10pub enum Span {
11    /// Marks the end of a span.
12    End,
13    /// Marks the start of a span.
14    Start,
15}
16
17impl ToKey for Span {
18    fn to_key(&self) -> Key<'_> {
19        "span_mark".into()
20    }
21}
22
23impl ToValue for Span {
24    fn to_value(&self) -> Value<'_> {
25        match self {
26            Self::End => "end".into(),
27            Self::Start => "start".into(),
28        }
29    }
30}
31
32impl Source for Span {
33    fn visit<'kvs>(&'kvs self, visitor: &mut dyn Visitor<'kvs>) -> Result<(), Error> where Self: Sized {
34        visitor.visit_pair(self.to_key(), self.to_value())?;
35        Ok(())
36    }
37
38    #[inline]
39    fn count(&self) -> usize {
40        1
41    }
42}