Enum abi_stable::std_types::RResult [−][src]
#[repr(u8)]
pub enum RResult<T, E> {
ROk(T),
RErr(E),
}
Expand description
Ffi-safe equivalent of Result<T,E>
.
Variants
Implementations
Converts from RResult<T,E>
to RResult<&T,&E>
.
Example
assert_eq!(ROk::<u32,u32>(10).as_ref(),ROk(&10));
assert_eq!(RErr::<u32,u32>(5).as_ref(),RErr(&5));
Converts from RResult<T,E>
to RResult<&mut T,&mut E>
.
Example
assert_eq!(ROk::<u32,u32>(10).as_mut(),ROk(&mut 10));
assert_eq!(RErr::<u32,u32>(5).as_mut(),RErr(&mut 5));
Returns whether self
is an ROk
Example
assert_eq!(ROk::<u32,u32>(10).is_rok(),true);
assert_eq!(RErr::<u32,u32>(5).is_rok(),false);
Returns whether self
is an ROk
Example
assert_eq!(ROk::<u32,u32>(10).is_ok(),true);
assert_eq!(RErr::<u32,u32>(5).is_ok(),false);
Returns whether self
is an RErr
Example
assert_eq!(ROk::<u32,u32>(10).is_rerr(),false);
assert_eq!(RErr::<u32,u32>(5).is_rerr(),true);
Returns whether self
is an RErr
Example
assert_eq!(ROk::<u32,u32>(10).is_err(),false);
assert_eq!(RErr::<u32,u32>(5).is_err(),true);
Converts from RResult<T,E>
to Result<T,E>
.
Example
assert_eq!(ROk::<u32,u32>(10).into_result(),Ok (10));
assert_eq!(RErr::<u32,u32>(5).into_result(),Err(5));
Converts the RResult<T,E>
to a RResult<U,E>
by transforming the value in
ROk
using the op
closure.
Example
assert_eq!(ROk::<u32,u32>(10).map(|x| x*3 ),ROk(30));
assert_eq!(RErr::<u32,u32>(5).map(|x| x/2 ),RErr(5));
Converts the RResult<T,E>
to a RResult<U,F>
by
transforming the value in RErr
using the op
closure.
Example
assert_eq!(ROk::<u32,u32>(10).map_err(|x| x*3 ),ROk(10));
assert_eq!(RErr::<u32,u32>(5).map_err(|x| x/2 ),RErr(2));
pub fn map_or_else<U, M, F>(self, with_err: F, with_ok: M) -> U where
M: FnOnce(T) -> U,
F: FnOnce(E) -> U,
pub fn map_or_else<U, M, F>(self, with_err: F, with_ok: M) -> U where
M: FnOnce(T) -> U,
F: FnOnce(E) -> U,
Converts the RResult<T,E>
to a U
by
transforming the value in ROk
using the with_ok
closure,
otherwise transforming the value in RErr using the with_err
closure,
Example
assert_eq!(ROk::<u32,u32>(10).map_or_else(|_|77 ,|x| x*3 ),30);
assert_eq!(RErr::<u32,u32>(5).map_or_else(|e|e*4,|x| x/2 ),20);
Returns the result of calling the op
closure with the value in ROk
,
otherwise returning the RErr
unmodified.
Example
assert_eq!(
ROk::<u32,u32>(10).and_then(|x| ROk ::<u32,u32>(x*3) ),
ROk (30),
);
assert_eq!(
ROk::<u32,u32>(10).and_then(|x| RErr::<u32,u32>(x*3)),
RErr(30),
);
assert_eq!(
RErr::<u32,u32>(5).and_then(|x| ROk ::<u32,u32>(x/2) ),
RErr(5),
);
assert_eq!(
RErr::<u32,u32>(5).and_then(|x| RErr::<u32,u32>(x/2) ),
RErr(5),
);
Returns the result of calling the op
closure with the value in RErr
,
otherwise returning the ROk
unmodified.
Example
assert_eq!(ROk::<u32,u32>(10).or_else(|e| ROk ::<u32,u32>(e*3) ) ,ROk(10));
assert_eq!(ROk::<u32,u32>(10).or_else(|e| RErr::<u32,u32>(e*3)) ,ROk(10));
assert_eq!(RErr::<u32,u32>(5).or_else(|e| ROk ::<u32,u32>(e/2) ),ROk (2));
assert_eq!(RErr::<u32,u32>(5).or_else(|e| RErr::<u32,u32>(e/2) ),RErr(2));
Unwraps self
, returning the value in RErr
.
Panic
Panics with an error message if self
is an ROk
,
using T
s Debug implementation,
as well as message
.
Example
assert_eq!( RErr::<(),u32>(0xB001).expect_err("Murphy's law"), 0xB001 );
This one panics:
let _=ROk::<(),()>(()).expect_err("Everything is Ok");
Returns the value in ROk
,or def
if self
is RErr
.
Example
assert_eq!(ROk::<u32,u32>(10).unwrap_or(0xEEEE),10);
assert_eq!(RErr::<u32,u32>(5).unwrap_or(0b101010),0b101010);
Returns the value in ROk
,
or calls def
with the error in RErr
.
Example
assert_eq!(ROk::<u32,u32>(10).unwrap_or_else(|e| e*3 ),10);
assert_eq!(RErr::<u32,u32>(5).unwrap_or_else(|e| e/2 ),2);
Returns the value in ROk
,
or returns T::default()
it self
is an RErr
.
Example
assert_eq!(ROk::<u32,u32>(10).unwrap_or_default(),10);
assert_eq!(RErr::<u32,u32>(5).unwrap_or_default(),0);
Converts from RResult<T, E>
to ROption<T>
,
ROk
maps to RSome
,RErr
maps to RNone
.
Example
assert_eq!(ROk::<u32,u32>(10).ok(),RSome(10));
assert_eq!(RErr::<u32,u32>(5).ok(),RNone);
Trait Implementations
impl<'de, T, E> Deserialize<'de> for RResult<T, E> where
T: Deserialize<'de>,
E: Deserialize<'de>,
impl<'de, T, E> Deserialize<'de> for RResult<T, E> where
T: Deserialize<'de>,
E: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
type StaticEquivalent = _static_RResult<__GetStaticEquivalent<T>, __GetStaticEquivalent<E>>
type Module = M
type Module = M
The module that is loaded in the success case.
Performs the conversion
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, E> RefUnwindSafe for RResult<T, E> where
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> UnwindSafe for RResult<T, E> where
E: UnwindSafe,
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.