Skip to main content

IndirectCauses

Struct IndirectCauses 

Source
pub struct IndirectCauses<M = &'static Metadata<'static>>
where M: Clone + Debug,
{ /* private fields */ }
Expand description

The indirect (follows_from) causes of a Span.

Implementations§

Source§

impl<M> IndirectCauses<M>
where M: Clone + Debug,

Source

pub fn contains(&self, span: &Span<M>) -> bool

Returns true if the given id is among this span’s indirect causes.

use std::sync::Arc;
use tracing::{Subscriber, trace_span};
use tracing_causality::{self as causality, data::IndirectCauses};
use tracing_subscriber::{prelude::*, registry::{LookupSpan, SpanData, Registry}};

let subscriber: Arc<dyn Subscriber + Send + Sync > =
    Arc::new(Registry::default().with(causality::Layer));
subscriber.clone().init();
let subscriber: Arc<dyn Subscriber> = subscriber;
let registry = subscriber.downcast_ref::<Registry>().unwrap();

let root = trace_span!("root");
let root_id_and_metadata = causality::Span {
    id: root.id().unwrap(),
    metadata: root.metadata().unwrap()
};
let consequence = trace_span!("consequence");
let consequence_id_and_metadata = causality::Span {
    id: consequence.id().unwrap(),
    metadata: consequence.metadata().unwrap()
};
consequence.follows_from(&root_id_and_metadata.id);
consequence.follows_from(&consequence_id_and_metadata.id);

let consequence_data = registry.span_data(&consequence_id_and_metadata.id).unwrap();
let consequence_extensions = consequence_data.extensions();
let consequence_causes = consequence_extensions.get::<IndirectCauses>().unwrap();
assert!(consequence_causes.contains(&root_id_and_metadata));
assert!(consequence_causes.contains(&consequence_id_and_metadata));
Source

pub fn iter(&self) -> impl Iterator<Item = &Span<M>>

Produces an iterator over this span’s indirect causes.

use std::sync::Arc;
use tracing::{Subscriber, trace_span};
use tracing_causality::{self as causality, data::IndirectCauses};
use tracing_subscriber::{prelude::*, registry::{LookupSpan, SpanData, Registry}};

let subscriber: Arc<dyn Subscriber + Send + Sync > =
    Arc::new(Registry::default().with(causality::Layer));
subscriber.clone().init();
let subscriber: Arc<dyn Subscriber> = subscriber;
let registry = subscriber.downcast_ref::<Registry>().unwrap();

let root = trace_span!("root");
let root_id_and_metadata = causality::Span {
    id: root.id().unwrap(),
    metadata: root.metadata().unwrap()
};
let consequence = trace_span!("consequence");
let consequence_id_and_metadata = causality::Span {
    id: consequence.id().unwrap(),
    metadata: consequence.metadata().unwrap()
};
consequence.follows_from(&root_id_and_metadata.id);

let consequence_data = registry.span_data(&consequence_id_and_metadata.id).unwrap();
let consequence_extensions = consequence_data.extensions();
let consequence_causes = consequence_extensions.get::<IndirectCauses>().unwrap();
assert_eq!(
    consequence_causes.iter().next(),
    Some(&root_id_and_metadata)
);

Auto Trait Implementations§

§

impl<M> Freeze for IndirectCauses<M>

§

impl<M> RefUnwindSafe for IndirectCauses<M>
where M: RefUnwindSafe,

§

impl<M> Send for IndirectCauses<M>
where M: Send,

§

impl<M> Sync for IndirectCauses<M>
where M: Sync,

§

impl<M> Unpin for IndirectCauses<M>
where M: Unpin,

§

impl<M> UnsafeUnpin for IndirectCauses<M>

§

impl<M> UnwindSafe for IndirectCauses<M>
where M: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.