#[cfg(feature = "iter")]
mod option_iterators;
#[cfg(feature = "iter")]
pub use self::option_iterators::*;
#[doc(inline)]
pub use crate::__opt_unwrap_or as unwrap_or;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_unwrap_or {
($e:expr, $v:expr $(,)?) => {
match $crate::option::__opt_and_val($e, $v) {
($crate::__::Some(x), _) => x,
($crate::__::None, value) => value,
}
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!()]
#[doc(inline)]
pub use crate::__opt_unwrap_or_else as unwrap_or_else;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_unwrap_or_else {
($e:expr, || $v:expr $(,)?) => {
match $crate::option::__opt($e) {
opt => {
let ret = if let $crate::__::Some(_) = opt {
$crate::__::Option::unwrap(opt)
} else {
$crate::option::__unwrap_or_else_helper(opt, $v)
};
ret
}
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take no arguments")
};
($e:expr, $v:path $(,)?) => {
$crate::__opt_unwrap_or_else! {$e, || $v()}
};
}
#[doc(inline)]
pub use crate::__opt_ok_or as ok_or;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_ok_or {
($e:expr, $v:expr $(,)?) => {
match ($crate::option::__opt($e), $v) {
($crate::__::Some(x), _) => $crate::__::Ok(x),
($crate::__::None, value) => $crate::__::Err(value),
}
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!()]
#[doc(inline)]
pub use crate::__opt_ok_or_else as ok_or_else;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_ok_or_else {
($e:expr, || $v:expr $(,)?) => {
match $crate::option::__opt($e) {
opt => {
if let $crate::__::Some(_) = opt {
$crate::__::Ok($crate::__::Option::unwrap(opt))
} else {
$crate::__::forget(opt);
$crate::__::Err($v)
}
}
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take no arguments")
};
($e:expr, $v:path $(,)?) => {
$crate::__opt_ok_or_else! {$e, || $v()}
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!("")]
#[doc(inline)]
pub use crate::__opt_map as map;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_map {
($opt:expr, |$param:pat_param| $mapper:expr $(,)? ) => {
match $crate::option::__opt($opt) {
opt => {
if let $crate::__::Some(_) = opt {
let $param = $crate::__::Option::unwrap(opt);
$crate::__::Some($mapper)
} else {
$crate::__::forget(opt);
$crate::__::None
}
}
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, || $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, $function:path $(,)?) => {
$crate::__opt_map! {$opt, |x| $function(x)}
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!("")]
#[doc(inline)]
pub use crate::__opt_and_then as and_then;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_and_then {
($opt:expr, |$param:pat_param| $mapper:expr $(,)? ) => {
match $crate::option::__opt($opt) {
opt => {
if let $crate::__::Some(_) = opt {
let $param = $crate::__::Option::unwrap(opt);
let ret: $crate::__::Option<_> = $mapper;
ret
} else {
$crate::__::forget(opt);
$crate::__::None
}
}
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, || $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, $function:path $(,)?) => {
$crate::__opt_and_then! {$opt, |x| $function(x)}
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!()]
#[doc(inline)]
pub use crate::__opt_or_else as or_else;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_or_else {
($opt:expr, || $mapper:expr $(,)? ) => {
match $crate::option::__opt($opt) {
opt @ $crate::__::Some(_) => opt,
mut opt @ $crate::__::None => {
$crate::__utils::__overwrite(&mut opt, $mapper);
opt
}
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take no arguments")
};
($opt:expr, $function:path $(,)?) => {
$crate::__opt_or_else! {$opt, || $function()}
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!("")]
#[doc(inline)]
pub use crate::__opt_filter as filter;
#[doc(hidden)]
#[macro_export]
macro_rules! __opt_filter {
($e:expr, |$param:pat_param| $v:expr $(,)?) => {
match $crate::option::__opt($e) {
opt @ $crate::__::Some(x)
if {
let $param = &x;
$v
} =>
{
opt
}
_ => $crate::__::None,
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, || $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($e:expr, $function:path $(,)?) => {
match $crate::option::__opt($e) {
$crate::__::Some(x) if $function(&x) => $crate::__::Some(x),
_ => $crate::__::None,
}
};
}
#[doc(inline)]
pub use crate::__get_or_insert as get_or_insert;
#[doc(hidden)]
#[macro_export]
macro_rules! __get_or_insert {
($opt:expr, $inserted:expr $(,)?) => {
match $crate::option::__optmut_val($opt, $inserted) {
($crate::__::Some(val), _inserted) => val,
(opt @ None, inserted) => {
$crate::option::__overwrite_some(opt, inserted);
let ret = $crate::option::__unwrap_mut(opt);
ret
}
}
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!()]
#[doc(inline)]
pub use crate::__get_or_insert_with as get_or_insert_with;
#[doc(hidden)]
#[macro_export]
macro_rules! __get_or_insert_with {
($opt:expr, || $default:expr $(,)?) => {
match $crate::__optmut!($opt).reff {
$crate::__::Some(val) => val,
opt @ None => {
$crate::option::__overwrite_some(opt, $default);
let ret = $crate::option::__unwrap_mut(opt);
ret
}
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take no arguments")
};
($opt:expr, $default:path $(,)?) => {
$crate::option::get_or_insert_with!($opt, || $default())
};
}
#[doc(inline)]
pub use crate::__option_insert as insert;
#[doc(hidden)]
#[macro_export]
macro_rules! __option_insert {
($opt:expr, $inserted:expr $(,)?) => {
match $crate::option::__optmut_val($opt, $inserted) {
(opt, val) => {
*opt = $crate::__::Some(val);
let ret = $crate::option::__unwrap_mut(opt);
ret
}
}
};
}
#[doc(inline)]
pub use crate::__option_zip as zip;
#[doc(hidden)]
#[macro_export]
macro_rules! __option_zip {
($left:expr, $right:expr) => {
match $crate::option::__opt_pair($left, $right) {
(left, right) => {
$crate::if_let_Some! {l = left => {
$crate::if_let_Some!{r = right => {
$crate::__::Some((l, r))
} else {
$crate::__::None
}}
} else {
$crate::__::None
}}
}
}
};
}
pub const fn unzip<T, U>(opt: Option<(T, U)>) -> (Option<T>, Option<U>) {
crate::if_let_Some! {tuple = opt => {
crate::destructure!{(l, r) = tuple}
(Some(l), Some(r))
} else {
(None, None)
}}
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!("")]
#[doc(inline)]
pub use crate::__option_is_some_and as is_some_and;
#[doc(hidden)]
#[macro_export]
macro_rules! __option_is_some_and {
($opt:expr, |$param:pat_param| $pred:expr $(,)?) => {
match $crate::__optref!(&$opt).reff {
$crate::__::Some(reff) => {
let $param = reff;
$pred
}
$crate::__::None => false,
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, || $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, $pred:path $(,)?) => {
$crate::option::is_some_and!($opt, |x| $pred(x))
};
}
#[doc = crate::docs::closure_arg_pattern_limitations_docs!("")]
#[doc(inline)]
pub use crate::__option_is_none_or as is_none_or;
#[doc(hidden)]
#[macro_export]
macro_rules! __option_is_none_or {
($opt:expr, |$param:pat_param| $pred:expr $(,)?) => {
match $crate::__optref!(&$opt).reff {
$crate::__::Some(reff) => {
let $param = reff;
$pred
}
$crate::__::None => true,
}
};
($opt:expr, | $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, || $($anything:tt)* ) => {
$crate::__::compile_error!("expected the closure to take a pattern as an argument")
};
($opt:expr, $pred:path $(,)?) => {
$crate::option::is_none_or!($opt, |x| $pred(x))
};
}
#[doc(hidden)]
pub struct __OptRef<'a, T> {
pub reff: &'a Option<T>,
}
#[doc(hidden)]
#[macro_export]
macro_rules! __optref {
($($reff:tt)*) => {
$crate::option::__OptRef { reff: $($reff)* }
}
}
#[doc(hidden)]
pub struct __OptMut<'a, T> {
pub reff: &'a mut Option<T>,
}
#[doc(hidden)]
#[macro_export]
macro_rules! __optmut {
($($reff:tt)*) => {
$crate::option::__OptMut { reff: $($reff)* }
}
}
#[inline(always)]
#[doc(hidden)]
pub const fn __opt<T>(opt: Option<T>) -> Option<T> {
opt
}
#[inline(always)]
#[doc(hidden)]
pub const fn __opt_pair<T, U>(l: Option<T>, r: Option<U>) -> (Option<T>, Option<U>) {
(l, r)
}
#[inline(always)]
#[doc(hidden)]
pub const fn __opt_and_val<T>(opt: Option<T>, val: T) -> (Option<T>, T) {
(opt, val)
}
#[inline(always)]
#[doc(hidden)]
pub const fn __optmut_val<T>(opt: &mut Option<T>, val: T) -> (&mut Option<T>, T) {
(opt, val)
}
#[inline(always)]
#[doc(hidden)]
pub const fn __unwrap_or_else_helper<T>(opt: Option<T>, val: T) -> T {
core::mem::forget(opt);
val
}
#[inline(always)]
#[doc(hidden)]
#[track_caller]
pub const fn __unwrap_mut<T>(opt: &mut Option<T>) -> &mut T {
match opt {
Some(x) => x,
None => __panic_on_none(),
}
}
#[inline(always)]
#[doc(hidden)]
#[track_caller]
pub const fn __overwrite_some<T>(opt: &mut Option<T>, val: T) {
crate::__utils::__overwrite(opt, Some(val))
}
#[cold]
#[track_caller]
const fn __panic_on_none() -> ! {
panic!("called `Option::unwrap()` on a `None` value")
}