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

The consequences — direct and indirect — of a Span.

Implementations

Constructs a new, empty Consequences.

Constructs a Consequences with the given direct consequence.

Constructs a Consequences with the given indirect consequence.

Add the given direct consequence.

Add the given indirect consequence.

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));

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));

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)
);

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.