pub struct Frame { /* private fields */ }
Expand description

A single context or attachment inside of a Report.

Frames 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

Returns the location where this Frame was created.

Returns a shared reference to the source of this Frame.

This corresponds to the Frame below this one in a Report.

Returns a mutable reference to the source of this Frame.

This corresponds to the Frame below this one in a Report.

Returns how the Frame was created.

Examples found in repository?
examples/json_output.rs (line 62)
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(())
}
Available on nightly only.

Requests the reference to T from the Frame if provided.

Available on nightly only.

Requests the value of T from the Frame if provided.

Returns if T is the held context or attachment by this frame.

Downcasts this frame if the held context or attachment is the same as T.

Downcasts this frame if the held context or attachment is the same as T.

Trait Implementations

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Data providers should implement this method to provide all values they are able to provide by using demand. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more