pub struct Because { /* private fields */ }Expand description
A report on its way out of the library, with the chain a caller can walk.
The report is still there whole - Deref reaches it, and
so do facts::all and a {:?} of it - and beside it
sits the same thing as an ordinary error chain, built the first time
somebody asks and not before. A failure that nobody looks into costs the
report it was already carrying and nothing more.
Implementations§
Source§impl Because
impl Because
pub fn new(why: Report<StorageError>) -> Self
Sourcepub fn into_report(self) -> Report<StorageError>
pub fn into_report(self) -> Report<StorageError>
The report, for the plumbing under the boundary.
Methods from Deref<Target = Report<StorageError>>§
Sourcepub fn current_frame(&self) -> &Frame
pub fn current_frame(&self) -> &Frame
Returns the direct current frames of this report.
To get an iterator over the topological sorting of all frames refer to frames().
This is not the same as Report::current_context, this function gets the underlying
frames that make up this report, while Report::current_context traverses the stack of
frames to find the current context. A Report and be made up of multiple Frames,
which stack on top of each other. Considering PrintableA<PrintableA<Context>>,
Report::current_frame will return the “outer” layer PrintableA, while
Report::current_context will return the underlying Error (the current type
parameter of this Report).
A report can be made up of multiple stacks of frames and builds a “group” of them, this can
be achieved through first calling Report::expand and then either using Extend
or Report::push.
Sourcepub fn current_context(&self) -> &C
pub fn current_context(&self) -> &C
Returns the current context of the Report.
If the user want to get the latest context, current_context can be called. If the user
wants to handle the error, the context can then be used to directly access the context’s
type. This is only possible for the latest context as the Report does not have multiple
generics as this would either require variadic generics or a workaround like tuple-list.
This is one disadvantage of the library in comparison to plain Errors, as in these cases, all context types are known.
§Example
use std::io;
fn read_file(path: impl AsRef<Path>) -> Result<String, Report<io::Error>> {
...
}
let report = read_file("test.txt").unwrap_err();
let io_error = report.current_context();
assert_eq!(io_error.kind(), io::ErrorKind::NotFound);Sourcepub fn as_error(&self) -> &(impl Error + Send + Sync + 'static)where
C: 'static,
pub fn as_error(&self) -> &(impl Error + Send + Sync + 'static)where
C: 'static,
Returns this Report as an Error.
Sourcepub fn request_ref<T>(&self) -> RequestRef<'_, T> ⓘ
pub fn request_ref<T>(&self) -> RequestRef<'_, T> ⓘ
Sourcepub fn request_value<T>(&self) -> RequestValue<'_, T> ⓘ
pub fn request_value<T>(&self) -> RequestValue<'_, T> ⓘ
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>
pub fn downcast_ref<T>(&self) -> Option<&T>
Searches the frame stack for a context provider T and returns the most recent context
found.
T can either be an attachment or a new Error context.
§Example
use std::io;
fn read_file(path: impl AsRef<Path>) -> Result<String, Report<io::Error>> {
...
}
let report = read_file("test.txt").unwrap_err();
let io_error = report.downcast_ref::<io::Error>().unwrap();
assert_eq!(io_error.kind(), io::ErrorKind::NotFound);