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
impl Trace
Sourcepub fn kv(&mut self, key: impl Into<Cow<'static, str>>, value: impl Display)
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.
Sourcepub fn entries(&self) -> Vec<TraceEntry>
pub fn entries(&self) -> Vec<TraceEntry>
The breadcrumbs recorded in the active trace so far, oldest first.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more