Enum abi_stable::std_types::ROption [−][src]
#[repr(u8)]
pub enum ROption<T> {
RSome(T),
RNone,
}
Expand description
Ffi-safe equivalent of the std::option::Option
type.
Option
is also ffi-safe for NonNull/NonZero types,and references.
Variants
Implementations
Converts from ROption<T>
to ROption<&T>
.
Example
assert_eq!(RSome(10) .as_ref(),RSome(&10));
assert_eq!(RNone::<u32>.as_ref(),RNone );
Converts from ROption<T>
to ROption<&mut T>
.
Example
assert_eq!(RSome(10) .as_mut(),RSome(&mut 10));
assert_eq!(RNone::<u32>.as_mut(),RNone );
Returns whether self
is an RSome
Example
assert_eq!(RSome(10) .is_rsome(),true);
assert_eq!(RNone::<u32>.is_rsome(),false);
Returns whether self
is an RNone
Example
assert_eq!(RSome(10) .is_rnone(),false);
assert_eq!(RNone::<u32>.is_rnone(),true);
Returns whether self
is an RSome
Example
assert_eq!(RSome(10) .is_some(),true);
assert_eq!(RNone::<u32>.is_some(),false);
Returns whether self
is an RNone
Example
assert_eq!(RSome(10) .is_none(),false);
assert_eq!(RNone::<u32>.is_none(),true);
Converts from ROption<T>
to Option<T>
.
Example
assert_eq!(RSome(10) .into_option(),Some(10));
assert_eq!(RNone::<u32>.into_option(),None );
Returns the value in the ROption<T>
,or def
if self
is RNone
.
Example
assert_eq!(RSome(10) .unwrap_or(99),10);
assert_eq!(RNone::<u32>.unwrap_or(99),99);
Returns the value in the ROption<T>
,or T::default()
if self
is RNone
.
Example
assert_eq!(RSome(10) .unwrap_or_default(),10);
assert_eq!(RNone::<u32>.unwrap_or_default(),0);
Returns the value in the ROption<T>
,
or the return value of calling f
if self
is RNone
.
Example
assert_eq!(RSome(10) .unwrap_or_else(|| 77 ),10);
assert_eq!(RNone::<u32>.unwrap_or_else(|| 77 ),77);
Converts the ROption<T>
to a ROption<U>
,
transforming the contained value with the f
closure.
Example
assert_eq!(RSome(10) .map(|x| x*2 ),RSome(20));
assert_eq!(RNone::<u32>.map(|x| x*2 ),RNone);
Transforms (and returns) the contained value with the f
closure,
or returns default
if self
is RNone
.
Example
assert_eq!(RSome(10) .map_or(77,|x| x*2 ),20);
assert_eq!(RNone::<u32>.map_or(77,|x| x*2 ),77);
pub fn map_or_else<U, D, F>(self, otherwise: D, f: F) -> U where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
pub fn map_or_else<U, D, F>(self, otherwise: D, f: F) -> U where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
Transforms (and returns) the contained value with the f
closure,
or returns otherwise()
if self
is RNone
..
Example
assert_eq!(RSome(10) .map_or_else(||77,|x| x*2 ),20);
assert_eq!(RNone::<u32>.map_or_else(||77,|x| x*2 ),77);
Returns self
if predicate(&self)
is true,otherwise returns RNone
.
Example
assert_eq!(RSome(10).filter(|x| (x%2)==0 ),RSome(10));
assert_eq!(RSome(10).filter(|x| (x%2)==1 ),RNone );
assert_eq!(RNone::<u32>.filter(|_| true ),RNone );
assert_eq!(RNone::<u32>.filter(|_| false ),RNone );
Returns self
if it is RNone
,otherwise returns optb
.
Example
assert_eq!(RSome(10).and(RSome(20)),RSome(20));
assert_eq!(RSome(10).and(RNone ),RNone);
assert_eq!(RNone::<u32>.and(RSome(20)),RNone);
assert_eq!(RNone::<u32>.and(RNone ),RNone);
Returns self
if it is RNone
,
otherwise returns the result of calling f
with the value in RSome
.
Example
assert_eq!(RSome(10).and_then(|x|RSome(x * 2)),RSome(20));
assert_eq!(RSome(10).and_then(|_|RNone::<u32>),RNone);
assert_eq!(RNone::<u32>.and_then(|x|RSome(x * 2)),RNone);
assert_eq!(RNone::<u32>.and_then(|_|RNone::<u32>),RNone);
Returns self
if it contains a value, otherwise returns optb
.
Example
assert_eq!(RSome(10).or(RSome(20)),RSome(10));
assert_eq!(RSome(10).or(RNone ),RSome(10));
assert_eq!(RNone::<u32>.or(RSome(20)),RSome(20));
assert_eq!(RNone::<u32>.or(RNone ),RNone);
Returns self
if it contains a value,
otherwise calls optb
and returns the value it evaluates to.
Example
assert_eq!(RSome(10).or_else(|| RSome(20) ),RSome(10));
assert_eq!(RSome(10).or_else(|| RNone ),RSome(10));
assert_eq!(RNone::<u32>.or_else(|| RSome(20) ),RSome(20));
assert_eq!(RNone::<u32>.or_else(|| RNone ),RNone);
Returns RNone
if both values are RNone
or RSome
,
otherwise returns the value that is anRSome
.
Example
assert_eq!(RSome(10).xor(RSome(20)),RNone );
assert_eq!(RSome(10).xor(RNone ),RSome(10));
assert_eq!(RNone::<u32>.xor(RSome(20)),RSome(20));
assert_eq!(RNone::<u32>.xor(RNone ),RNone );
Sets this ROption to RSome(value)
if it was RNone
.
Returns a mutable reference to the inserted/pre-existing RSome
.
Example
assert_eq!(RSome(10).get_or_insert(40),&mut 10);
assert_eq!(RSome(20).get_or_insert(55),&mut 20);
assert_eq!(RNone::<u32>.get_or_insert(77),&mut 77);
Sets this ROption
to RSome(func())
if it was RNone
.
Returns a mutable reference to the inserted/pre-existing RSome
.
Example
assert_eq!(RSome(10).get_or_insert_with(||40),&mut 10);
assert_eq!(RSome(20).get_or_insert_with(||55),&mut 20);
assert_eq!(RNone::<u32>.get_or_insert_with(||77),&mut 77);
Takes the value of self
,replacing it with RNone
Example
let mut opt0=RSome(10);
assert_eq!(opt0.take(),RSome(10));
assert_eq!(opt0,RNone);
let mut opt1=RSome(20);
assert_eq!(opt1.take(),RSome(20));
assert_eq!(opt1,RNone);
let mut opt2=RNone::<u32>;
assert_eq!(opt2.take(),RNone);
assert_eq!(opt2,RNone);
Replaces the value of self
with RSome(value)
.
Example
let mut opt0=RSome(10);
assert_eq!(opt0.replace(55),RSome(10));
assert_eq!(opt0,RSome(55));
let mut opt1=RSome(20);
assert_eq!(opt1.replace(88),RSome(20));
assert_eq!(opt1,RSome(88));
let mut opt2=RNone::<u32>;
assert_eq!(opt2.replace(33),RNone);
assert_eq!(opt2,RSome(33));
Converts an ROption<&T>
to an ROption<T>
by cloning its contents.
Example
assert_eq!(RSome(&vec![()]).cloned(),RSome(vec![()]));
assert_eq!(RNone::<&Vec<()>>.cloned(),RNone );
Converts an ROption<&mut T>
to a ROption<T>
by cloning its contents.
Example
assert_eq!(RSome(&mut vec![()]).cloned(),RSome(vec![()]));
assert_eq!(RNone::<&mut Vec<()>>.cloned(),RNone );
Trait Implementations
The default value is RNone
.
Deserialize this value from the given Serde deserializer. Read more
type StaticEquivalent = _static_ROption<__GetStaticEquivalent<T>>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
type IsNonZeroType = False
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
The layout of the type provided by implementors.
const
-equivalents of the associated types.
Auto Trait Implementations
impl<T> RefUnwindSafe for ROption<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for ROption<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type ROwned = T
type ROwned = T
The owned type, stored in RCow::Owned
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
Compares the address of self
with the address of other
. Read more
Emulates the pipeline operator, allowing method syntax in more places. Read more
The same as piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more
The same as piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read more
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Performs a conversion with Into
.
using the turbofish .into_::<_>()
syntax. Read more
Performs a reference to reference conversion with AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more
Performs a mutable reference to mutable reference conversion with AsMut
,
using the turbofish .as_mut_::<_>()
syntax. Read more
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
Converts a mutable reference back to the original type.
Converts a box back to the original type.
Converts an Arc back to the original type. Read more
Converts an Rc back to the original type. Read more
Converts a value back to the original type.
Converts a reference back to the original type.
Converts a mutable reference back to the original type.
Converts a box back to the original type.
Converts an Arc back to the original type.
Converts an Rc back to the original type.