pub struct Trace<T>(/* private fields */);Expand description
A stack-like structure to hold the module backtrace during evaluation.
A module trace is to the evaluator what Backtrace is to a program. In
the trace, modules are stored in import-order. This means that the module
where the error was caused is always the last one in the trace.
Implementations§
Source§impl<T> Trace<T>
impl<T> Trace<T>
Sourcepub fn push(&mut self, id: T)
pub fn push(&mut self, id: T)
Add a module to the trace.
Pushing a module makes that module the “deepest” level of the trace.
See: Trace.
§Example
let mut trace = Trace::empty();
trace.push("module 1");
trace.push("module 2");
trace.push("module 3");
assert_eq!(
trace.iter().copied().collect::<Vec<_>>(),
&[
"module 1",
"module 2",
"module 3"
]
);Sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Remove the last module from the trace and return it.
Also see: push.
§Example
let mut trace = Trace::empty();
trace.push("module 1");
trace.push("module 2");
trace.push("module 3");
assert_eq!(trace.pop(), Some("module 3"));
assert_eq!(trace.pop(), Some("module 2"));
assert_eq!(trace.pop(), Some("module 1"));
assert_eq!(trace.pop(), None);Sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Get an iterator over all modules in the trace.
The returned iterator traverses the trace from the deepest module to the
shallowest. The returned iterator implements DoubleEndedIterator so
you can use Iterator::rev.
§Example
let mut trace = Trace::empty();
trace.push("module 1");
trace.push("module 2");
trace.push("module 3");
let mut iter = trace.iter();
assert_eq!(iter.next().copied(), Some("module 1"));
assert_eq!(iter.next().copied(), Some("module 2"));
assert_eq!(iter.next().copied(), Some("module 3"));
assert_eq!(iter.next().copied(), None);Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Trace<T>
impl<T> RefUnwindSafe for Trace<T>where
T: RefUnwindSafe,
impl<T> Send for Trace<T>where
T: Send,
impl<T> Sync for Trace<T>where
T: Sync,
impl<T> Unpin for Trace<T>where
T: Unpin,
impl<T> UnsafeUnpin for Trace<T>
impl<T> UnwindSafe for Trace<T>where
T: UnwindSafe,
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