macro_rules! take {
    ($p: expr) => { ... };
    ($p: expr,) => { ... };
}
Expand description

Takes out the value from a reference.

Usage

let mut x = 42;
assert_eq!(omniswap::take!(&mut x), 42);

It also supports references to cells: &Cell<T> and &RefCell<T>.

Requirements

It requires the value type to satisfy Default or Clone.

If multiple traits can apply, the behavior is determined in the following order:

  1. If T: Copy it copies the value from the seference.
  2. Otherwise, if T: Default, it swaps the value with the default value.
  3. Otherwise, if T: Clone, it clones out the value from the reference.

Additionally, if the reference is &Cell<T>, T must satisfy Default or Copy. Clone alone does not suffice.