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 be transferred 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 recoverable "owned" parameters that were passed so that the caller can have them back.

Implementations

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]

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]

impl<T> Display for Error<T>[src]

impl<T> Error for Error<T> where
    T: Debug
[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Error<T> where
    T: RefUnwindSafe
[src]

impl<T> Send for Error<T> where
    T: Send
[src]

impl<T> Sync for Error<T> where
    T: Sync
[src]

impl<T> Unpin for Error<T> where
    T: Unpin
[src]

impl<T> UnwindSafe for Error<T> where
    T: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.