[−][src]Macro ward::guard
Creates a variable with the contents of a Option<T>
's Some(T)
, otherwise it returns early
from the function.
Examples
// res is set to sut's contents let sut = Some("test"); guard!(let res = sut); assert_eq!("test", res);
// Because sut is None, the guard! returns early let sut = None; guard!(let mut res = sut); unreachable!();
// Because sut is None, the guard!'s else branch will be run before it returns early let sut = None; guard!(let _res = sut, else { println!("This code will run!"); }); unreachable!();