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

RSome(T)

Tuple Fields of RSome

0: T
RNone

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

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:


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

Unwraps the ROption, returning its contents.

Panics

Panics if self is RNone.

Example


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

This one panics:


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

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

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<&T> to an ROption<T> by Copy-ing its contents.

Example


assert_eq!(RSome(&7).copied(),RSome(7));
assert_eq!(RNone::<&u32>.copied(),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    );

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The default value is RNone.

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Performs the conversion.

The #[repr(Rust)] equivalent.

Performs the conversion

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

The owned type, stored in RCow::Owned

The borrowed type, stored in RCow::Borrowed

Performs the conversion.

This is always WithMetadata_<Self, Self>

Performs the conversion.

Gets a reference to a field, determined by offset. Read more

Gets a muatble reference to a field, determined by offset. Read more

Gets a const pointer to a field, the field is determined by offset. Read more

Gets a mutable pointer to a field, determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

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

Drops self using method notation. Alternative to std::mem::drop. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Transmutes the element type of this pointer.. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This is always Self.

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. 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.