Struct error_stack::Frame
source · [−]pub struct Frame { /* private fields */ }
Expand description
A single context or attachment inside of a Report
.
Frame
s are organized as a singly linked list, which can be iterated by calling
Report::frames()
. The head contains the current context or attachment, and the tail contains
the root context created by Report::new()
. The next Frame
can be accessed by requesting it
by calling Report::request_ref()
.
Implementations
sourceimpl Frame
impl Frame
sourcepub const fn location(&self) -> &'static Location<'static>
pub const fn location(&self) -> &'static Location<'static>
Returns the location where this Frame
was created.
sourcepub const fn source(&self) -> Option<&Self>
pub const fn source(&self) -> Option<&Self>
Returns a shared reference to the source of this Frame
.
This corresponds to the Frame
below this one in a Report
.
sourcepub fn source_mut(&mut self) -> Option<&mut Self>
pub fn source_mut(&mut self) -> Option<&mut Self>
Returns a mutable reference to the source of this Frame
.
This corresponds to the Frame
below this one in a Report
.
sourcepub fn kind(&self) -> FrameKind<'_>
pub fn kind(&self) -> FrameKind<'_>
Returns how the Frame
was created.
Examples found in repository?
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
fn main() -> Result<(), MapError> {
// This hook will be executed instead of the default implementation when `Debug` is called
Report::set_debug_hook(|report, fmt| {
#[derive(Serialize)]
struct Context {
context: String,
attachments: Vec<String>,
}
let mut output = Vec::new();
let mut attachments = Vec::new();
for frame in report.frames() {
match frame.kind() {
FrameKind::Context(context) => {
output.push(Context {
context: context.to_string(),
attachments: attachments.clone(),
});
attachments.clear();
}
FrameKind::Attachment(AttachmentKind::Printable(attachment)) => {
attachments.push(attachment.to_string());
}
FrameKind::Attachment(_) => {}
}
}
if fmt.alternate() {
fmt.write_str(&serde_json::to_string_pretty(&output).expect("Could not format report"))
} else {
fmt.write_str(&serde_json::to_string(&output).expect("Could not format report"))
}
})
.expect("Hook was set twice");
let mut config = HashMap::default();
// Create an entry with "foo" as key
create_new_entry(&mut config, "foo", 1).attach_printable("Could not create new entry")?;
// Purposefully cause an error by attempting to create another entry with "foo" as key
create_new_entry(&mut config, "foo", 2).attach_printable("Could not create new entry")?;
// Will output something like
// ```json
// [
// {
// "context": "Entry \"foo\" is already occupied by 1",
// "attachments": [
// "Could not create new entry"
// ]
// }
// ]
// ```
Ok(())
}
sourcepub fn request_ref<T>(&self) -> Option<&T> where
T: ?Sized + 'static,
Available on nightly
only.
pub fn request_ref<T>(&self) -> Option<&T> where
T: ?Sized + 'static,
nightly
only.Requests the reference to T
from the Frame
if provided.
sourcepub fn request_value<T>(&self) -> Option<T> where
T: 'static,
Available on nightly
only.
pub fn request_value<T>(&self) -> Option<T> where
T: 'static,
nightly
only.Requests the value of T
from the Frame
if provided.
sourcepub fn is<T: Send + Sync + 'static>(&self) -> bool
pub fn is<T: Send + Sync + 'static>(&self) -> bool
Returns if T
is the held context or attachment by this frame.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Frame
impl Send for Frame
impl Sync for Frame
impl Unpin for Frame
impl UnwindSafe for Frame
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more