err

Macro err 

Source
macro_rules! err {
    (not_found, $e: expr) => { ... };
    (permission_denied, $e: expr) => { ... };
    (conn_refused, $e: expr) => { ... };
    (conn_reset, $e: expr) => { ... };
    (host_unreachable, $e: expr) => { ... };
    (net_unreachable, $e: expr) => { ... };
    (conn_aborted, $e: expr) => { ... };
    (not_connected, $e: expr) => { ... };
    (in_use, $e: expr) => { ... };
    (addr_not_available, $e: expr) => { ... };
    (net_down, $e: expr) => { ... };
    (broken_pipe, $e: expr) => { ... };
    (already_exists, $e: expr) => { ... };
    (would_block, $e: expr) => { ... };
    (not_a_dir, $e: expr) => { ... };
    (is_a_dir, $e: expr) => { ... };
    (dir_not_empty, $e: expr) => { ... };
    (read_only_fs, $e: expr) => { ... };
    (fs_loop, $e: expr) => { ... };
    (stale_net_filehandle, $e: expr) => { ... };
    (invalid_input, $e: expr) => { ... };
    (invalid_data, $e: expr) => { ... };
    (timeout, $e: expr) => { ... };
    (write_zero, $e: expr) => { ... };
    (storage_full, $e: expr) => { ... };
    (not_seekable, $e: expr) => { ... };
    (fs_quota_exceeded, $e: expr) => { ... };
    (file_too_large, $e: expr) => { ... };
    (resource_busy, $e: expr) => { ... };
    (executable_busy, $e: expr) => { ... };
    (deadlock, $e: expr) => { ... };
    (crosses_devices, $e: expr) => { ... };
    (too_many_links, $e: expr) => { ... };
    (filename_too_long, $e: expr) => { ... };
    (argument_list_too_long, $e: expr) => { ... };
    (interrupted, $e: expr) => { ... };
    (unsupported, $e: expr) => { ... };
    (unexpected_eof, $e: expr) => { ... };
    (out_of_memory, $e: expr) => { ... };
    (other, $e: expr) => { ... };
    (uncategorized, $e: expr) => { ... };
    ($p: ident, $e: expr) => { ... };
    (($($t: tt)*)) => { ... };
    (@$i: ident) => { ... };
    ($e: expr) => { ... };
    ($p: ident, $fmt:expr, $($arg:tt)*) => { ... };
    ($fmt:expr, $($arg:tt)*) => { ... };
}
Expand description

construct an io error rapidly

let error = err!(other, "another error");
let other = err!("another unspecified error, will be categorized as `Other`");
let result = err!(("this error will be encapsulated under an Err()"));
fn chosen_one<T>(ty: T) -> Result<T> {
    if random() {
        // unspecified errors will always be classified as `Other`
        err!(("you died in the process"))? // this will return early
    } else if !chosen() {
        err!((permission_denied, "you are not the chosen one"))?
    }
    Ok(ty)
}