option take

  • https://doc.rust-lang.org/std/option/enum.Option.html#method.take
  • Takes the value out of the option, leaving a None in its place.

signiture

pub fn take(&mut self) -> Option<T>

example

let mut x = Some(2);
let y = x.take();
assert_eq!(x, None);
assert_eq!(y, Some(2));

let mut x: Option<u32> = None;
let y = x.take();
assert_eq!(x, None);
assert_eq!(y, None);