[][src]Enum abi_stable::std_types::ROption

#[repr(u8)]pub enum ROption<T> {
    RSome(T),
    RNone,
}

Ffi-safe equivalent of the std::option::Option type.

Option is also ffi-safe for NonNull/NonZero types,and references.

Variants

RSome(T)
RNone

Implementations

impl<T> ROption<T>[src]

pub fn as_ref(&self) -> ROption<&T>[src]

Converts from ROption<T> to ROption<&T>.

Example


assert_eq!(RSome(10)   .as_ref(),RSome(&10));
assert_eq!(RNone::<u32>.as_ref(),RNone     );

pub fn as_mut(&mut self) -> ROption<&mut T>[src]

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 );

pub fn is_rsome(&self) -> bool[src]

Returns whether self is an RSome

Example


assert_eq!(RSome(10)   .is_rsome(),true);
assert_eq!(RNone::<u32>.is_rsome(),false);

pub fn is_rnone(&self) -> bool[src]

Returns whether self is an RNone

Example


assert_eq!(RSome(10)   .is_rnone(),false);
assert_eq!(RNone::<u32>.is_rnone(),true);

pub fn is_some(&self) -> bool[src]

Returns whether self is an RSome

Example


assert_eq!(RSome(10)   .is_some(),true);
assert_eq!(RNone::<u32>.is_some(),false);

pub fn is_none(&self) -> bool[src]

Returns whether self is an RNone

Example


assert_eq!(RSome(10)   .is_none(),false);
assert_eq!(RNone::<u32>.is_none(),true);

pub fn into_option(self) -> Option<T>[src]

Converts from ROption<T> to Option<T>.

Example


assert_eq!(RSome(10)   .into_option(),Some(10));
assert_eq!(RNone::<u32>.into_option(),None     );

pub fn expect(self, msg: &str) -> T[src]

Unwraps the ROption<T>, returning its contents.

Panics

Panics if self is RNone, with the msg message.

Example


assert_eq!( RSome(100).expect("must contain a value"), 100 );

This one panics:

This example panics

let _=RNone::<()>.expect("Oh noooo!");

pub fn unwrap(self) -> T[src]

Unwraps the ROption, returning its contents.

Panics

Panics if self is RNone.

Example


assert_eq!( RSome(500).unwrap(), 500 );

This one panics:

This example panics

let _=RNone::<()>.unwrap();

pub fn unwrap_or(self, def: T) -> T[src]

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);

pub fn unwrap_or_default(self) -> T where
    T: Default
[src]

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);

pub fn unwrap_or_else<F>(self, f: F) -> T where
    F: FnOnce() -> T, 
[src]

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);

pub fn map<U, F>(self, f: F) -> ROption<U> where
    F: FnOnce(T) -> U, 
[src]

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);

pub fn map_or<U, F>(self, default: U, f: F) -> U where
    F: FnOnce(T) -> U, 
[src]

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, 
[src]

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);

pub fn filter<P>(self, predicate: P) -> Self where
    P: FnOnce(&T) -> bool
[src]

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    );

pub fn and(self, optb: ROption<T>) -> ROption<T>[src]

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);

pub fn and_then<F, U>(self, f: F) -> ROption<U> where
    F: FnOnce(T) -> ROption<U>, 
[src]

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);

pub fn or(self, optb: ROption<T>) -> ROption<T>[src]

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);

pub fn or_else<F>(self, f: F) -> ROption<T> where
    F: FnOnce() -> ROption<T>, 
[src]

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);

pub fn xor(self, optb: ROption<T>) -> ROption<T>[src]

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    );

pub fn get_or_insert(&mut self, value: T) -> &mut T[src]

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);

pub fn get_or_insert_with<F>(&mut self, func: F) -> &mut T where
    F: FnOnce() -> T, 
[src]

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);

pub fn take(&mut self) -> ROption<T>[src]

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);

pub fn replace(&mut self, value: T) -> ROption<T>[src]

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));

impl<T, '_> ROption<&'_ T>[src]

pub fn cloned(self) -> ROption<T> where
    T: Clone
[src]

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        );

pub fn copied(self) -> ROption<T> where
    T: Copy
[src]

Converts an ROption<&T> to an ROption<T> by Copy-ing its contents.

Example


assert_eq!(RSome(&7).copied(),RSome(7));
assert_eq!(RNone::<&u32>.copied(),RNone);

impl<T, '_> ROption<&'_ mut T>[src]

pub fn cloned(self) -> ROption<T> where
    T: Clone
[src]

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    );

pub fn copied(self) -> ROption<T> where
    T: Copy
[src]

Converts an ROption<&mut T> to a ROption<T> by Copy-ing its contents.

Example


assert_eq!(RSome(&mut 7).copied(),RSome(7));
assert_eq!(RNone::<&mut u32>.copied(),RNone   );

Trait Implementations

impl<T: Clone> Clone for ROption<T>[src]

impl<T: Copy> Copy for ROption<T>[src]

impl<T: Debug> Debug for ROption<T>[src]

impl<T> Default for ROption<T>[src]

The default value is RNone.

impl<'de, T> Deserialize<'de> for ROption<T> where
    T: Deserialize<'de>, 
[src]

impl<T: Eq> Eq for ROption<T>[src]

impl<T> From<Option<T>> for ROption<T>[src]

impl<T> GetStaticEquivalent_ for ROption<T> where
    T: __StableAbi
[src]

type StaticEquivalent = _static_ROption<__GetStaticEquivalent<T>>

impl<T: Hash> Hash for ROption<T>[src]

impl<T> Into<Option<T>> for ROption<T>[src]

impl<T> IntoReprRust for ROption<T>[src]

type ReprRust = Option<T>

The #[repr(Rust)] equivalent.

impl<T: Ord> Ord for ROption<T>[src]

impl<T: PartialEq> PartialEq<ROption<T>> for ROption<T>[src]

impl<T: PartialOrd> PartialOrd<ROption<T>> for ROption<T>[src]

impl<T> Serialize for ROption<T> where
    T: Serialize
[src]

impl<T> StableAbi for ROption<T> where
    T: __StableAbi
[src]

type IsNonZeroType = False

Whether this type has a single invalid bit-pattern. Read more

impl<T> StructuralEq for ROption<T>[src]

impl<T> StructuralPartialEq for ROption<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for ROption<T> where
    T: RefUnwindSafe

impl<T> Send for ROption<T> where
    T: Send

impl<T> Sync for ROption<T> where
    T: Sync

impl<T> Unpin for ROption<T> where
    T: Unpin

impl<T> UnwindSafe for ROption<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<'a, T> BorrowOwned<'a> for T where
    T: 'a + Clone
[src]

type ROwned = T

The owned type, stored in RCow::Owned

type RBorrowed = &'a T

The borrowed type, stored in RCow::Borrowed

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T> GetWithMetadata for T[src]

type ForSelf = WithMetadata_<T, T>

This is always WithMetadata_<Self, Self>

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SelfOps for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<This> TransmuteElement for This where
    This: ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The error type returned when the conversion fails.

impl<T> TypeIdentity for T where
    T: ?Sized
[src]

type Type = T

The same type as Self. Read more

impl<This> ValidTag_Bounds for This where
    This: Debug + Clone + PartialEq<This>, 
[src]