Skip to main content

Trace

Struct Trace 

Source
pub struct Trace { /* private fields */ }
Expand description

A scoped collector of in-test breadcrumbs.

Construct one at the top of a test; every TestError built before it is dropped carries a snapshot of the breadcrumbs recorded so far, and renders them in the failure output.

use test_better_core::Trace;

let mut trace = Trace::new();
trace.step("connecting to db");
trace.kv("db_url", "postgres://localhost/test");
trace.step("running the query");
// If an assertion fails here, these three breadcrumbs are attached to the
// resulting `TestError` and shown, in order, in the rendered failure.

Dropping the Trace ends the scope. Nested traces compose: an inner Trace::new() displaces the outer trace’s entries and restores them on drop, so the outer trace resumes intact.

Implementations§

Source§

impl Trace

Source

pub fn new() -> Trace

Starts a trace, collecting breadcrumbs until it is dropped.

Source

pub fn step(&mut self, message: impl Into<Cow<'static, str>>)

Records a narrative step.

Source

pub fn kv(&mut self, key: impl Into<Cow<'static, str>>, value: impl Display)

Records a key/value breadcrumb, rendering value with Display now, so the breadcrumb is not tied to the value’s lifetime.

Source

pub fn entries(&self) -> Vec<TraceEntry>

The breadcrumbs recorded in the active trace so far, oldest first.

Trait Implementations§

Source§

impl Default for Trace

Source§

fn default() -> Trace

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

impl Drop for Trace

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Freeze for Trace

§

impl RefUnwindSafe for Trace

§

impl Send for Trace

§

impl Sync for Trace

§

impl Unpin for Trace

§

impl UnsafeUnpin for Trace

§

impl UnwindSafe for Trace

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

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