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

ROk(T)

Tuple Fields of ROk

0: T
RErr(E)

Tuple Fields of RErr

0: E

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

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


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

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:


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

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:


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

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:


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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. 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

The module that is loaded in the success case.

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.