pub enum Tree {
Event(Event),
Span(Span),
}Available on crate feature
forest only.Expand description
Variants§
Implementations§
Source§impl Tree
impl Tree
Sourcepub fn event(&self) -> Result<&Event, ExpectedEventError>
pub fn event(&self) -> Result<&Event, ExpectedEventError>
Returns a reference to the inner Event if the tree is an event.
§Errors
This function returns an error if the Tree contains the Span variant.
§Examples
Collect a completed tree with a channel and inspect its event:
use gix_trace::{ForestLayer, forest::{processor, tree::Event}};
use tracing_subscriber::layer::SubscriberExt;
let (sender, receiver) = std::sync::mpsc::channel();
let processor = processor::from_fn(move |tree| {
sender.send(tree).expect("the receiver lives until the tree is inspected");
Ok(())
});
let subscriber = tracing_subscriber::Registry::default().with(ForestLayer::from(processor));
tracing::subscriber::with_default(subscriber, || {
tracing::info!("some information");
});
let tree = receiver.recv()?;
let event: &Event = tree.event()?;
assert_eq!(event.message(), Some("some information"), "the event retains its message");Sourcepub fn span(&self) -> Result<&Span, ExpectedSpanError>
pub fn span(&self) -> Result<&Span, ExpectedSpanError>
Returns a reference to the inner Span if the tree is a span.
§Errors
This function returns an error if the Tree contains the Event variant.
§Examples
Collect a completed tree with a channel and inspect its span:
use gix_trace::{ForestLayer, forest::{processor, tree::Span}};
use tracing_subscriber::layer::SubscriberExt;
let (sender, receiver) = std::sync::mpsc::channel();
let processor = processor::from_fn(move |tree| {
sender.send(tree).expect("the receiver lives until the tree is inspected");
Ok(())
});
let subscriber = tracing_subscriber::Registry::default().with(ForestLayer::from(processor));
tracing::subscriber::with_default(subscriber, || {
tracing::info_span!("my_span").in_scope(|| tracing::info!("inside the span"));
});
let tree = receiver.recv()?;
let span: &Span = tree.span()?;
assert_eq!(span.name(), "my_span", "the completed span retains its name");Trait Implementations§
Auto Trait Implementations§
impl Forget for Tree
impl Freeze for Tree
impl Move for Tree
impl RefUnwindSafe for Tree
impl Send for Tree
impl Sync for Tree
impl Unpin for Tree
impl UnsafeUnpin for Tree
impl UnwindSafe for Tree
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more