[][src]Macro doublysure::make_sure

macro_rules! make_sure {
    ($name:ident($($arg:expr),*)) => { ... };
    ($code:block) => { ... };
    ($value:expr) => { ... };
}

Macro to wrap values in an AreYouSure. Or in other words, it makes sure of something.

Creates an AreYouSure, possibly deferring execution of a function or block of code.

Variants

This macro has three variants, each with their own use cases.

You can wrap a value or expression directly.


let sure = make_sure!(4 + 1);
let x = sure.yes_i_am_sure();
assert_eq!(x, 5);

You can defer a function. While it looks like min() is called here, it will actually be called later when yes_i_am_sure() is called. This means that functions with destructive side effects cannot happen until you have confirmed you are sure.


let sure = make_sure!(std::cmp::min(4, 5));
let x = sure.yes_i_am_sure();
assert_eq!(x, 4);

Finally you can defer a block of code for later execution. Keep in mind you still need the parentheses around the block. This form requires the most care to use. Keep in mind as well that the return value of the block is the last expression without a ; and not the return.


let sure = make_sure!({
  let x = 4;
  let y = 5;
  std::cmp::min(x, y)
});
let x = sure.yes_i_am_sure();
assert_eq!(x, 4);