Update

Enum Update 

Source
pub enum Update<M = &'static Metadata<'static>>
where M: Clone + Debug,
{ OpenDirect { cause: Span<M>, consequence: Span<M>, }, NewIndirect { cause: Span<M>, consequence: Span<M>, }, CloseDirect { span: Span<M>, direct_cause: Option<Span<M>>, }, CloseIndirect { span: Span<M>, indirect_causes: Vec<Span<M>>, }, CloseCyclic { span: Span<M>, direct_cause: Option<Span<M>>, indirect_causes: Vec<Span<M>>, }, }
Expand description

An update that should be applied to a Trace.

Variants§

§

OpenDirect

Announces that consequence directly follows from cause.

§Example

use std::sync::Arc;
use tracing::Subscriber;
use tracing_causality::{self as causality, Update};
use tracing_subscriber::{prelude::*, registry::Registry};

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

    let cause = tracing::trace_span!("cause");
    let cause_id_and_metadata = causality::Span {
        id: cause.id().unwrap(),
        metadata: cause.metadata().unwrap()
    };

    let (_trace, cause_updates) = causality::trace(registry, &cause_id_and_metadata.id, 1024).unwrap();

    let consequence = cause.in_scope(|| tracing::trace_span!("consequence"));
    let consequence_id_and_metadata = causality::Span {
        id: consequence.id().unwrap(),
        metadata: consequence.metadata().unwrap()
    };

    assert_eq!(
        cause_updates.drain().collect::<Vec<_>>(),
        vec![Update::OpenDirect {
            cause: cause_id_and_metadata,
            consequence: consequence_id_and_metadata,
        }],
        "The listeners on `cause` should be notified that it has a \
        direct `consequence`."
    );
}

Fields

§cause: Span<M>
§consequence: Span<M>
§

NewIndirect

Announces that consequence indirectly follows from cause.

§Example

use std::sync::Arc;
use tracing::Subscriber;
use tracing_causality::{self as causality, Update};
use tracing_subscriber::{prelude::*, registry::Registry};

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

    let cause = tracing::trace_span!("cause");
    let cause_id_and_metadata = causality::Span {
        id: cause.id().unwrap(),
        metadata: cause.metadata().unwrap()
    };

    let (_trace, cause_updates) = causality::trace(registry, &cause_id_and_metadata.id, 1024).unwrap();

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

    assert_eq!(
        cause_updates.drain().collect::<Vec<_>>(),
        vec![Update::NewIndirect {
            cause: cause_id_and_metadata.clone(),
            consequence: consequence_id_and_metadata.clone(),
        }],
        "The listeners on `cause` should be notified that it has a \
        indirect `consequence`."
    );
}

Fields

§cause: Span<M>
§consequence: Span<M>
§

CloseDirect

Announces that a direct consequence of a Span within Trace was closed, and is thus no longer an extant consequence of direct_cause.

§Example

use std::sync::Arc;
use tracing::Subscriber;
use tracing_causality::{self as causality, Update};
use tracing_subscriber::{prelude::*, registry::Registry};

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

    let cause = tracing::trace_span!("cause");
    let cause_id_and_metadata = causality::Span {
        id: cause.id().unwrap(),
        metadata: cause.metadata().unwrap()
    };

    let consequence = cause.in_scope(|| tracing::trace_span!("consequence"));
    let consequence_id_and_metadata = causality::Span {
        id: consequence.id().unwrap(),
        metadata: consequence.metadata().unwrap()
    };

    let (_trace, cause_updates) = causality::trace(registry, &cause_id_and_metadata.id, 1024).unwrap();

    drop(consequence);

    assert_eq!(
        cause_updates.drain().collect::<Vec<_>>(),
        vec![Update::CloseDirect {
            span: consequence_id_and_metadata.clone(),
            direct_cause: Some(cause_id_and_metadata),
        }],
        "The listeners on `cause` should be notified that
        `consequence` was closed."
    );
}

Fields

§span: Span<M>
§direct_cause: Option<Span<M>>
§

CloseIndirect

Announces that an indirect consequence of a Span within Trace was closed, and is thus no longer an extant consequence of indirect_causes.

§Example

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

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

    let cause = tracing::trace_span!("cause");
    let cause_id_and_metadata = causality::Span {
        id: cause.id().unwrap(),
        metadata: cause.metadata().unwrap()
    };

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

    consequence.follows_from(&cause_id_and_metadata.id);

    let (_trace, cause_updates) = causality::trace(registry, &cause_id_and_metadata.id, 1024).unwrap();

    drop(consequence);

    assert_eq!(
        cause_updates.drain().collect::<Vec<_>>(),
        vec![Update::CloseIndirect {
            span: consequence_id_and_metadata,
            indirect_causes: vec![cause_id_and_metadata],
        }],
        "The listeners on `cause` should be notified that
        `consequence` was closed."
    );
}

Fields

§span: Span<M>
§indirect_causes: Vec<Span<M>>
§

CloseCyclic

Announces that a self-cycling consequence of a Span within Trace was closed, and is thus no longer an extant consequence of direct_cause or indirect_cause.

§Example

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

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

    let cause = tracing::trace_span!("cause");
    let cause_id_and_metadata = causality::Span {
        id: cause.id().unwrap(),
        metadata: cause.metadata().unwrap()
    };

    let consequence = cause.clone();
    let consequence_id_and_metadata = causality::Span {
        id: consequence.id().unwrap(),
        metadata: consequence.metadata().unwrap()
    };

    consequence.follows_from(&cause_id_and_metadata.id);

    let (_trace, cause_updates) = causality::trace(registry, &cause_id_and_metadata.id, 1024).unwrap();

    drop([cause, consequence]);

    assert_eq!(
        cause_updates.into_iter().collect::<Vec<_>>(),
        vec![Update::CloseCyclic {
            span: consequence_id_and_metadata.clone(),
            direct_cause: None,
            indirect_causes: vec![cause_id_and_metadata.clone()],
        }],
        "The listeners on `cause` should be notified that
        `consequence` was closed."
    );
}

Fields

§span: Span<M>
§direct_cause: Option<Span<M>>
§indirect_causes: Vec<Span<M>>

Trait Implementations§

Source§

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

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<M> Debug for Update<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> PartialEq for Update<M>
where M: Clone + Debug + PartialEq,

Source§

fn eq(&self, other: &Update<M>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Update<M>
where M: Clone + Debug + Eq,

Auto Trait Implementations§

§

impl<M> Freeze for Update<M>
where M: Freeze,

§

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

§

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

§

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

§

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

§

impl<M> UnwindSafe for Update<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.