Struct scratchpad::Error
[−]
[src]
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.
Methods
impl<T> Error<T>
[src]
pub fn new(kind: ErrorKind, args: T) -> Self
[src]
Creates a new error with the specified category and argument values.
Examples
use scratchpad::{Error, ErrorKind}; // Error containing multiple recycled arguments. let multi_error = Error::new( ErrorKind::MarkerLocked, (3.14159f32, 2.71828f32), ); // Error containing a single recycled argument. A tuple is still used // to remain consistent with errors that recycle multiple argument // values. let single_error = Error::new(ErrorKind::MarkerLocked, (3.14159f32,)); // Error containing no recycled argument values. A unit is used by the // crate to signify an empty set of arguments. let simple_error = Error::new(ErrorKind::MarkerLocked, ());
pub fn kind(&self) -> ErrorKind
[src]
Returns the category of error that occurred.
Examples
use scratchpad::{Error, ErrorKind}; let error = Error::new( ErrorKind::MarkerLocked, (3.14159f32, 2.71828f32), ); let kind = error.kind(); assert_eq!(kind, ErrorKind::MarkerLocked);
pub fn args(&self) -> &T
[src]
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.
Examples
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));
pub fn unwrap_args(self) -> T
[src]
Unwraps the error, yielding a tuple containing values that would have passed ownership to the callee if the operation was successful.
Examples
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);
pub fn map<U, F>(self, op: F) -> Error<U> where
F: FnOnce(T) -> U,
[src]
F: FnOnce(T) -> U,
Maps an Error<T>
to an Error<U>
by applying a function to the
contained arguments value, leaving the ErrorKind
value untouched.
Examples
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);
Trait Implementations
impl<T: Debug> Debug for Error<T>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T> Display for Error<T>
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T> Error for Error<T> where
T: Debug,
[src]
T: Debug,