[][src]Enum abi_stable::std_types::RResult

#[repr(u8)]pub enum RResult<T, E> {
    ROk(T),
    RErr(E),
}

Ffi-safe equivalent of Result<T,E>.

Variants

ROk(T)
RErr(E)

Implementations

impl<T, E> RResult<T, E>[src]

pub fn as_ref(&self) -> RResult<&T, &E>[src]

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

pub fn as_mut(&mut self) -> RResult<&mut T, &mut E>[src]

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

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

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

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

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

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

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

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

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

pub fn into_result(self) -> Result<T, E>[src]

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

pub fn map<U, F>(self, op: F) -> RResult<U, E> where
    F: FnOnce(T) -> U, 
[src]

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

pub fn map_err<F, O>(self, op: O) -> RResult<T, F> where
    O: FnOnce(E) -> F, 
[src]

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

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

pub fn and_then<U, F>(self, op: F) -> RResult<U, E> where
    F: FnOnce(T) -> RResult<U, E>, 
[src]

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

pub fn or_else<F, O>(self, op: O) -> RResult<T, F> where
    O: FnOnce(E) -> RResult<T, F>, 
[src]

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

pub fn unwrap(self) -> T where
    E: Debug
[src]

Unwraps self, returning the value in ROk.

Panic

Panics with an error message if self is an RErr, using Es Debug implementation.

Example


assert_eq!( ROk::<_,()>(500).unwrap(), 500 );

This one panics:

This example panics

let _=RErr::<(),_>("Oh noooo!").unwrap();

pub fn expect(self, message: &str) -> T where
    E: Debug
[src]

Unwraps self, returning the value in ROk.

Panic

Panics with an error message if self is an RErr, using Es Debug implementation, as well as message.

Example


assert_eq!( ROk::<_,()>(500).expect("Are you OK?"), 500 );

This one panics:

This example panics

let _=RErr::<(),_>(()).expect("This can't be!");

pub fn unwrap_err(self) -> E where
    T: Debug
[src]

Unwraps self, returning the value in RErr.

Panic

Panics with an error message if self is an ROk, using Ts Debug implementation.

Example


assert_eq!( RErr::<(),u32>(0xB007).unwrap_err(), 0xB007 );

This one panics:

This example panics

let _=ROk::<(),()>(()).unwrap_err();

pub fn expect_err(self, message: &str) -> E where
    T: Debug
[src]

Unwraps self, returning the value in RErr.

Panic

Panics with an error message if self is an ROk, using Ts Debug implementation, as well as message.

Example


assert_eq!( RErr::<(),u32>(0xB001).expect_err("Murphy's law"), 0xB001 );

This one panics:

This example panics

let _=ROk::<(),()>(()).expect_err("Everything is Ok");

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

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

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

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

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

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

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

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

pub fn err(self) -> ROption<E>[src]

Converts from RResult<T, E> to ROption<T>, ROk maps to RNone,RErr maps to RSome.

Example


assert_eq!(ROk::<u32,u32>(10).err(),RNone);
assert_eq!(RErr::<u32,u32>(5).err(),RSome(5));

Trait Implementations

impl<T: Clone, E: Clone> Clone for RResult<T, E>[src]

impl<T: Copy, E: Copy> Copy for RResult<T, E>[src]

impl<T: Debug, E: Debug> Debug for RResult<T, E>[src]

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

impl<T: Eq, E: Eq> Eq for RResult<T, E>[src]

impl<T, E> From<Result<T, E>> for RResult<T, E>[src]

impl<T, E> GetStaticEquivalent_ for RResult<T, E> where
    T: __StableAbi,
    E: __StableAbi
[src]

impl<T: Hash, E: Hash> Hash for RResult<T, E>[src]

impl<T, E> Into<Result<T, E>> for RResult<T, E>[src]

impl<T, E> IntoReprRust for RResult<T, E>[src]

type ReprRust = Result<T, E>

The #[repr(Rust)] equivalent.

impl<M: RootModule> IntoRootModuleResult for RResult<M, RBoxError>[src]

type Module = M

The module that is loaded in the success case.

impl<T: Ord, E: Ord> Ord for RResult<T, E>[src]

impl<T: PartialEq, E: PartialEq> PartialEq<RResult<T, E>> for RResult<T, E>[src]

impl<T: PartialOrd, E: PartialOrd> PartialOrd<RResult<T, E>> for RResult<T, E>[src]

impl<T, E> Serialize for RResult<T, E> where
    T: Serialize,
    E: Serialize
[src]

impl<T, E> StableAbi for RResult<T, E> where
    T: __StableAbi,
    E: __StableAbi
[src]

type IsNonZeroType = False

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

impl<T, E> StructuralEq for RResult<T, E>[src]

impl<T, E> StructuralPartialEq for RResult<T, E>[src]

Auto Trait Implementations

impl<T, E> RefUnwindSafe for RResult<T, E> where
    E: RefUnwindSafe,
    T: RefUnwindSafe

impl<T, E> Send for RResult<T, E> where
    E: Send,
    T: Send

impl<T, E> Sync for RResult<T, E> where
    E: Sync,
    T: Sync

impl<T, E> Unpin for RResult<T, E> where
    E: Unpin,
    T: Unpin

impl<T, E> UnwindSafe for RResult<T, E> where
    E: UnwindSafe,
    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]