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]

[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, ());

[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);

[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));

[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);

[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]

[src]

Formats the value using the given formatter. Read more

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

[src]

Formats the value using the given formatter. Read more

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

[src]

A short description of the error. Read more

1.0.0
[src]

The lower-level cause of this error, if any. Read more

Auto Trait Implementations

impl<T> Send for Error<T> where
    T: Send

impl<T> Sync for Error<T> where
    T: Sync