devela::code::result

Macro unwrap

Source
macro_rules! unwrap {
    (

      // Option<T>
      // ---------

      // Unwraps the contained `Some` value, or otherwise returns `None`.
      some? $value:expr ) => { ... };
    (
      // Unwraps the contained `Some` value, or panics if it's `None`.
      some $value:expr) => { ... };
    (
      // Unwraps the contained `Some` value, or panics with the given message if it's `None`.
      some_expect $value:expr, $message:literal) => { ... };
    (
      // Unwraps the contained `Some` value, or the given default if it's `None`.
      some_or $value:expr, $default:expr) => { ... };
    (
      // Transforms the `Option` into a `Result`, mapping `Some(T)` to `Ok(T)`,
      // and `None` to `Err($err)`.
      some_ok_or $value:expr, $err:expr) => { ... };
    (
      // Unwraps the contained `Some` value or otherwise returns Err($err).
      some_ok_or? $value:expr, $err:expr) => { ... };
    (

      // Result<T, E>
      // ------------

      // Unwraps the contained `Ok` value, or otherwise returns the `Err` value.
      ok? $value:expr ) => { ... };
    (
      // Unwraps the contained `Ok` value, or panics if it's `Err`.
      ok $value:expr ) => { ... };
    (
      // Unwraps the contained `Ok` value, or panics with the given message if it's `Err`.
      ok_expect $value:expr, $message:literal) => { ... };
    (
      // Unwraps the contained `Ok` value, or a provided default if it's `Err`.
      ok_or $value:expr, $default:expr) => { ... };
    (
      // Transforms the `Result` into an `Option`, mapping `Ok(T)` to `Some(T)`,
      // and `Err(_)` to `None`.
      ok_some $value:expr) => { ... };
    (
      // Unwraps the contained `Ok` value, otherwise returns `None`.
      ok_some? $value:expr) => { ... };
    (
      // Unwraps the contained `Err` value, or panics if it's `Ok`.
      err $value:expr ) => { ... };
    (
      // Unwraps the contained `Err` value, or panics the given message if it's `Ok`.
      err_expect $value:expr, $message:literal) => { ... };
    (
      // Unwraps the contained `Err` value, or a provided default if it's `Ok`.
      err_or $value:expr, $default:expr) => { ... };
    (
      // Transforms the `Result` into an `Option`, mapping `Err(E)` to `Some(E)`,
      // and `Ok(_)` to `None`.
      err_some $value:expr) => { ... };
    (
      // Unwraps the contained `Err` value, otherwise returns `None`.
      err_some? $value:expr) => { ... };
    (

      // OptRes<T, E>
      // ------------

      // Unwraps the contained `Some(Ok)` value,
      // or otherwise either returns the `Some(Err)` value or `None`.
      sok? $value:expr ) => { ... };
    (
      // Unwraps the contained `Some(Ok)` value,
      // or panics if it's `Some(Err)` or `None`.
      sok $value:expr ) => { ... };
    (
      // Unwraps the contained `Some(Ok)` value,
      // or panics with the given message if it's `Some(Err)` or `None`.
      sok_expect $value:expr, $message:literal) => { ... };
    (
      // Unwraps the contained `Some(Ok)` value,
      // or a provided default if it's `Some(Err)` or `None`.
      sok_or $value:expr, $default:expr) => { ... };
    (
      // Unwraps the contained `Some(Err)` value,
      // or panics if it's `Some(Ok)` or `None`.
      serr $value:expr ) => { ... };
    (
      // Unwraps the contained `Some(Err)` value,
      // or panics with the given message if it's `Some(Ok)` or `None`.
      serr_expect $value:expr, $message:literal) => { ... };
    (
      // Unwraps the contained `Some(Err)` value,
      // or a provided default if it's `Some(Ok)` or `None`.
      serr_or $value:expr, $default:expr) => { ... };
}
Expand description

An unwrapper macro that works in compile-time.

It supports unwrapping Option, Result and OptRes.