Enum tracing_forest::tree::Tree
source · pub enum Tree {
Event(Event),
Span(Span),
}
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
Inspecting a Tree
returned from capture
:
use tracing::{info, info_span};
use tracing_forest::tree::{Tree, Event};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let logs: Vec<Tree> = tracing_forest::capture()
.build()
.on(async {
info!("some information");
})
.await;
assert!(logs.len() == 1);
let event: &Event = logs[0].event()?;
assert!(event.message() == Some("some information"));
Ok(())
}
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
Inspecting a Tree
returned from capture
:
use tracing::{info, info_span};
use tracing_forest::tree::{Tree, Span};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let logs: Vec<Tree> = tracing_forest::capture()
.build()
.on(async {
info_span!("my_span").in_scope(|| {
info!("inside the span");
});
})
.await;
assert!(logs.len() == 1);
let my_span: &Span = logs[0].span()?;
assert!(my_span.name() == "my_span");
Ok(())
}
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Tree
impl Send for Tree
impl Sync for Tree
impl Unpin 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