1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#![macro_use] macro_rules! fail { ($expr:expr) => ( return Err(::std::convert::From::from($expr)); ) } macro_rules! ensure { ($expr:expr, $err_result:expr) => ( if !($expr) { fail!($err_result) } ) } macro_rules! unwrap_or { ($expr:expr, $or:expr) => ( match $expr { Some(x) => x, None => { $or } } ) } #[macro_export] macro_rules! raw_to_ref { ($expr:expr) => (unsafe { &mut *$expr}) }