pub struct Error<T> { /* fields omitted */ }
The error type for scratchpad operations.
Various scratchpad operations require ownership of some or all of their
parameters to the callee, such as for storage in a new allocation. If such
operations fail, the caller may still want to do something with the data
originally provided. This type encapsulates both the kind of error that
occurred and any "owned" parameters that were passed so that the caller
can have them back.
Creates a new error with the specified category and argument values.
use scratchpad::{Error, ErrorKind};
let multi_error = Error::new(
ErrorKind::MarkerLocked,
(3.14159f32, 2.71828f32),
);
let single_error = Error::new(ErrorKind::MarkerLocked, (3.14159f32,));
let simple_error = Error::new(ErrorKind::MarkerLocked, ());
Returns the category of error that occurred.
use scratchpad::{Error, ErrorKind};
let error = Error::new(
ErrorKind::MarkerLocked,
(3.14159f32, 2.71828f32),
);
let kind = error.kind();
assert_eq!(kind, ErrorKind::MarkerLocked);
Returns a tuple containing values that would have passed ownership to
the callee if the operation was successful.
While there's no constraint on the arguments type, this crate will
only ever produce errors that have either a unit or tuple for its
arguments, even if only a single value is returned to the caller.
use scratchpad::{Error, ErrorKind};
let error = Error::new(
ErrorKind::MarkerLocked,
(3.14159f32, 2.71828f32),
);
let args = error.args();
assert_eq!(args, &(3.14159f32, 2.71828f32));
Unwraps the error, yielding a tuple containing values that would have
passed ownership to the callee if the operation was successful.
use scratchpad::{Error, ErrorKind};
let error = Error::new(
ErrorKind::MarkerLocked,
(3.14159f32, 2.71828f32),
);
let (x, y) = error.unwrap_args();
assert_eq!(x, 3.14159f32);
assert_eq!(y, 2.71828f32);
Maps an Error<T>
to an Error<U>
by applying a function to the
contained arguments value, leaving the ErrorKind
value untouched.
use scratchpad::{Error, ErrorKind};
let error = Error::new(ErrorKind::MarkerLocked, (-12, 23));
let new_error = error.map(|args| (args.1 as i64 * -2,));
assert_eq!(new_error.args().0, -46i64);
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
The lower-level cause of this error, if any. Read more