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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use std::future::Future;
mod context;
mod future;
mod registry;
pub use context::{current_tree, TreeContext};
use flexstr::SharedStr;
pub use future::Instrumented;
pub use registry::{Config, ConfigBuilder, ConfigBuilderError, Registry, TreeRoot};
#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct Span(SharedStr);
impl Span {
pub(crate) fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl<S: AsRef<str>> From<S> for Span {
fn from(value: S) -> Self {
Self(SharedStr::from_ref(value))
}
}
impl std::fmt::Display for Span {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
pub trait InstrumentAwait: Future + Sized {
fn instrument_await(self, span: impl Into<Span>) -> Instrumented<Self, false> {
Instrumented::new(self, span.into())
}
fn verbose_instrument_await(self, span: impl Into<Span>) -> Instrumented<Self, true> {
Instrumented::new(self, span.into())
}
}
impl<F> InstrumentAwait for F where F: Future {}
#[cfg(test)]
mod tests;