[−][src]Enum abi_stable::std_types::option::ROption
Ffi-safe equivalent of the Option<_>
type.
Option<_>
is also ffi-safe for NonNull/NonZero types,and references.
Use ROption<_> when Option<_>
would not be viable.
Variants
Methods
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:
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:
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]
T: Default,
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]
F: FnOnce() -> T,
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]
F: FnOnce(T) -> U,
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]
F: FnOnce(T) -> U,
Transforms (and returns) the contained value with the f
closure,
or returns default
.
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, default: D, f: F) -> U where
D: FnOnce() -> U,
F: FnOnce(T) -> U,
[src]
D: FnOnce() -> U,
F: FnOnce(T) -> U,
Transforms (and returns) the contained value with the f
closure,
or returns the value default
returns when called.
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]
P: FnOnce(&T) -> bool,
Returns self
if preficate(&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>(self, f: F) -> ROption<T> where
F: FnOnce() -> ROption<T>,
[src]
F: FnOnce() -> ROption<T>,
Returns self
if it is RNone,
otherwise calls optb
with the value of RSome
.
Example
assert_eq!(RSome(10).and_then(||RSome(20)),RSome(20)); assert_eq!(RSome(10).and_then(||RNone ),RNone); assert_eq!(RNone::<u32>.and_then(||RSome(20)),RNone); assert_eq!(RNone::<u32>.and_then(||RNone ),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]
F: FnOnce() -> ROption<T>,
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 either RNone
or RSome
,
otherwise returns RSome
from either one.
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]
F: FnOnce() -> T,
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]
T: Clone,
Converts an Option<&T>
to a Option<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]
T: Copy,
Converts an Option<&T>
to a Option<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]
T: Clone,
Converts an Option<&mut T>
to a Option<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]
T: Copy,
Converts an Option<&mut T>
to a Option<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> IntoReprRust for ROption<T>
[src]
impl<T> GetStaticEquivalent_ for ROption<T> where
T: __StableAbi,
[src]
T: __StableAbi,
type StaticEquivalent = _static_ROption<__GetStaticEquivalent<T>>
impl<T> SharedStableAbi for ROption<T> where
T: __StableAbi,
[src]
T: __StableAbi,
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
type Kind = __ValueKind
The kind of abi stability of this type,there are 2: Read more
const S_LAYOUT: &'static TypeLayout
[src]
const S_ABI_CONSTS: AbiConsts
[src]
impl<T> Into<Option<T>> for ROption<T>
[src]
impl<T> From<Option<T>> for ROption<T>
[src]
impl<T: Clone> Clone for ROption<T>
[src]
impl<T: Copy> Copy for ROption<T>
[src]
impl<T> Default for ROption<T>
[src]
The default value is RNone.
impl<T: Eq> Eq for ROption<T>
[src]
impl<T: Ord> Ord for ROption<T>
[src]
fn cmp(&self, other: &ROption<T>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<T: PartialEq> PartialEq<ROption<T>> for ROption<T>
[src]
impl<T: PartialOrd> PartialOrd<ROption<T>> for ROption<T>
[src]
fn partial_cmp(&self, other: &ROption<T>) -> Option<Ordering>
[src]
fn lt(&self, other: &ROption<T>) -> bool
[src]
fn le(&self, other: &ROption<T>) -> bool
[src]
fn gt(&self, other: &ROption<T>) -> bool
[src]
fn ge(&self, other: &ROption<T>) -> bool
[src]
impl<T: Debug> Debug for ROption<T>
[src]
impl<T: Hash> Hash for ROption<T>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<'de, T> Deserialize<'de> for ROption<T> where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl<T> Serialize for ROption<T> where
T: Serialize,
[src]
T: Serialize,
Auto Trait Implementations
impl<T> Send for ROption<T> where
T: Send,
T: Send,
impl<T> Sync for ROption<T> where
T: Sync,
T: Sync,
impl<T> Unpin for ROption<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for ROption<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for ROption<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<This> GetConstGenericVTable for This where
This: StableAbi + Eq + PartialEq<This> + Debug + Send + Sync,
[src]
This: StableAbi + Eq + PartialEq<This> + Debug + Send + Sync,
const VTABLE: ConstGenericVTableFor<This>
[src]
impl<This> StableAbi for This where
This: SharedStableAbi<Kind = ValueKind>,
[src]
This: SharedStableAbi<Kind = ValueKind>,
const LAYOUT: &'static TypeLayout
[src]
const ABI_CONSTS: AbiConsts
[src]
impl<This> TransmuteElement for This where
This: ?Sized,
[src]
This: ?Sized,
unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr where
Self: CanTransmuteElement<T>,
Self::Target: Sized,
[src]
Self: CanTransmuteElement<T>,
Self::Target: Sized,
impl<'a, T> BorrowOwned<'a> for T where
T: 'a + Clone,
[src]
T: 'a + Clone,
type ROwned = T
type RBorrowed = &'a T
fn r_borrow(
&'a <T as BorrowOwned<'a>>::ROwned
) -> <T as BorrowOwned<'a>>::RBorrowed
[src]
&'a <T as BorrowOwned<'a>>::ROwned
) -> <T as BorrowOwned<'a>>::RBorrowed
fn r_to_owned(
<T as BorrowOwned<'a>>::RBorrowed
) -> <T as BorrowOwned<'a>>::ROwned
[src]
<T as BorrowOwned<'a>>::RBorrowed
) -> <T as BorrowOwned<'a>>::ROwned
fn deref_borrowed(&<T as BorrowOwned<'a>>::RBorrowed) -> &T
[src]
fn deref_owned(&<T as BorrowOwned<'a>>::ROwned) -> &T
[src]
fn from_cow_borrow(&'a T) -> <T as BorrowOwned<'a>>::RBorrowed
[src]
fn from_cow_owned(<T as ToOwned>::Owned) -> <T as BorrowOwned<'a>>::ROwned
[src]
fn into_cow_borrow(<T as BorrowOwned<'a>>::RBorrowed) -> &'a T
[src]
fn into_cow_owned(<T as BorrowOwned<'a>>::ROwned) -> <T as ToOwned>::Owned
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> TypeIdentity for T where
T: ?Sized,
[src]
T: ?Sized,
type Type = T
The same type as Self. Read more
fn into_type_val(self) -> Self::Type where
Self::Type: Sized,
[src]
Self::Type: Sized,
fn into_type_ref(&self) -> &Self::Type
[src]
fn into_type_mut(&mut self) -> &mut Self::Type
[src]
fn into_type_box(self: Box<Self>) -> Box<Self::Type>
[src]
fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>
[src]
fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>
[src]
fn from_type_val(this: Self::Type) -> Self where
Self::Type: Sized,
[src]
Self::Type: Sized,
fn from_type_ref(this: &Self::Type) -> &Self
[src]
fn from_type_mut(this: &mut Self::Type) -> &mut Self
[src]
fn from_type_box(this: Box<Self::Type>) -> Box<Self>
[src]
fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>
[src]
fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>
[src]
impl<T> SelfOps for T where
T: ?Sized,
[src]
T: ?Sized,
const T: PhantomData<fn() -> Self>
[src]
const T_D: PhantomData<Self>
[src]
fn assert_ty(self, _other: PhantomData<fn() -> Self>) -> Self
[src]
fn assert_ty_ref(&self, _other: PhantomData<fn() -> Self>) -> &Self
[src]
fn assert_ty_mut(&mut self, _other: PhantomData<fn() -> Self>) -> &mut Self
[src]
fn ty_(&self) -> PhantomData<fn() -> Self>
[src]
fn ty_d(&self) -> PhantomData<Self>
[src]
fn ty_inv(&self) -> PhantomData<fn(Self) -> Self>
[src]
fn ty_inv_ref(&self) -> PhantomData<Cell<&Self>>
[src]
fn eq_id(&self, other: &Self) -> bool
[src]
fn piped<F, U>(self, f: F) -> U where
F: FnOnce(Self) -> U,
[src]
F: FnOnce(Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> U where
F: FnOnce(&'a Self) -> U,
[src]
F: FnOnce(&'a Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U where
F: FnOnce(&'a mut Self) -> U,
[src]
F: FnOnce(&'a mut Self) -> U,
fn mutated<F>(self, f: F) -> Self where
F: FnOnce(&mut Self),
[src]
F: FnOnce(&mut Self),
fn observe<F>(self, f: F) -> Self where
F: FnOnce(&Self),
[src]
F: FnOnce(&Self),
fn into_<T>(self, PhantomData<fn() -> T>) -> T where
Self: Into<T>,
[src]
Self: Into<T>,
fn as_ref_<T>(&self) -> &T where
Self: AsRef<T>,
T: ?Sized,
[src]
Self: AsRef<T>,
T: ?Sized,
fn as_mut_<T>(&mut self) -> &mut T where
Self: AsMut<T>,
T: ?Sized,
[src]
Self: AsMut<T>,
T: ?Sized,
fn drop_(self)
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The error type returned when the conversion fails.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,