Skip to main content

Consequences

Struct Consequences 

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

The consequences — direct and indirect — of a Span.

Implementations§

Source§

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

Source

pub fn none() -> Self

Constructs a new, empty Consequences.

Source

pub fn with_direct(direct: Span<M>) -> Self

Constructs a Consequences with the given direct consequence.

Source

pub fn with_indirect(indirect: Span<M>) -> Self

Constructs a Consequences with the given indirect consequence.

Source

pub fn add_direct(&mut self, direct: Span<M>)

Add the given direct consequence.

Source

pub fn add_indirect(&mut self, indirect: Span<M>)

Add the given indirect consequence.

Source

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

Returns true if the given id is among this span’s direct consequences.

use std::sync::Arc;
use tracing::{Subscriber, trace_span};
use tracing_causality::{self as causality, Consequences};
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 = root.in_scope(|| trace_span!("consequence"));
let consequence_id_and_metadata = causality::Span {
    id: consequence.id().unwrap(),
    metadata: consequence.metadata().unwrap()
};

let root_data = registry.span_data(&root_id_and_metadata.id).unwrap();
let root_extensions = root_data.extensions();
let root_consequences = root_extensions.get::<Consequences>().unwrap();
assert!(root_consequences.contains_direct(&consequence_id_and_metadata));
Source

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

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

use std::sync::Arc;
use tracing::{Subscriber, trace_span};
use tracing_causality::{self as causality, Consequences};
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 root_data = registry.span_data(&root_id_and_metadata.id).unwrap();
let root_extensions = root_data.extensions();
let root_consequences = root_extensions.get::<Consequences>().unwrap();
assert!(root_consequences.contains_indirect(&consequence_id_and_metadata));
Source

pub fn iter_direct(&self) -> impl ExactSizeIterator<Item = Span<M>> + '_

An iterator visiting all direct consequences in arbitrary order.

use std::sync::Arc;
use tracing::{Subscriber, trace_span};
use tracing_causality::{self as causality, Consequences};
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 = root.in_scope(|| trace_span!("consequence"));
let consequence_id_and_metadata = causality::Span {
    id: consequence.id().unwrap(),
    metadata: consequence.metadata().unwrap()
};

let root_data = registry.span_data(&root_id_and_metadata.id).unwrap();
let root_extensions = root_data.extensions();
let root_consequences = root_extensions.get::<Consequences>().unwrap();
assert_eq!(
    root_consequences.iter_direct().next(),
    Some(consequence_id_and_metadata)
);
Source

pub fn iter_indirect(&self) -> impl ExactSizeIterator<Item = Span<M>> + '_

An iterator visiting all direct consequences in arbitrary order.

use std::sync::Arc;
use tracing::{Subscriber, trace_span};
use tracing_causality::{self as causality, Consequences};
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 root_data = registry.span_data(&root_id_and_metadata.id).unwrap();
let root_extensions = root_data.extensions();
let root_consequences = root_extensions.get::<Consequences>().unwrap();
assert_eq!(
    root_consequences.iter_indirect().next(),
    Some(consequence_id_and_metadata)
);

Trait Implementations§

Source§

impl<M> Clone for Consequences<M>
where M: Clone + Debug + Clone,

Source§

fn clone(&self) -> Consequences<M>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M> Debug for Consequences<M>
where M: Clone + Debug + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<M> Default for Consequences<M>
where M: Clone + Debug,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<M> PartialEq for Consequences<M>
where M: Clone + Debug,

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<M> Eq for Consequences<M>
where M: Clone + Debug,

Auto Trait Implementations§

§

impl<M> Freeze for Consequences<M>

§

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

§

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

§

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

§

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

§

impl<M> UnsafeUnpin for Consequences<M>

§

impl<M> UnwindSafe for Consequences<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.