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

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

Variants§

§

ROk(T)

§

RErr(E)

Implementations§

source§

impl<T, E> RResult<T, E>

source

pub const fn as_ref(&self) -> RResult<&T, &E>

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

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

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

pub const fn is_rok(&self) -> bool

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

pub const fn is_ok(&self) -> bool

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

pub const fn is_rerr(&self) -> bool

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

pub const fn is_err(&self) -> bool

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

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

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

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

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

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

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

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

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

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

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

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

pub fn unwrap(self) -> T
where E: Debug,

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

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

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!");
source

pub fn unwrap_err(self) -> E
where T: Debug,

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

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

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

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

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

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

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

pub fn unwrap_or_default(self) -> T
where T: Default,

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

pub fn ok(self) -> ROption<T>

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

pub fn err(self) -> ROption<E>

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§

source§

impl<T: Clone, E: Clone> Clone for RResult<T, E>

source§

fn clone(&self) -> RResult<T, E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, E: Debug> Debug for RResult<T, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T, E> From<RResult<T, E>> for Result<T, E>

source§

fn from(this: RResult<T, E>) -> Result<T, E>

Converts to this type from the input type.
source§

impl<T, E> From<Result<T, E>> for RResult<T, E>

source§

fn from(this: Result<T, E>) -> RResult<T, E>

Converts to this type from the input type.
source§

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

§

type StaticEquivalent = _static_RResult<<T as GetStaticEquivalent_>::StaticEquivalent, <E as GetStaticEquivalent_>::StaticEquivalent>

The 'static equivalent of Self
source§

impl<T: Hash, E: Hash> Hash for RResult<T, E>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T, E> IntoReprRust for RResult<T, E>

§

type ReprRust = Result<T, E>

The #[repr(Rust)] equivalent.
source§

fn into_rust(self) -> Self::ReprRust

Performs the conversion
source§

impl<M: RootModule> IntoRootModuleResult for RResult<M, RBoxError>

§

type Module = M

The module that is loaded in the success case.
source§

fn into_root_module_result(self) -> Result<M, RootModuleError>

Performs the conversion
source§

impl<T: Ord, E: Ord> Ord for RResult<T, E>

source§

fn cmp(&self, other: &RResult<T, E>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T: PartialEq, E: PartialEq> PartialEq for RResult<T, E>

source§

fn eq(&self, other: &RResult<T, E>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: PartialOrd, E: PartialOrd> PartialOrd for RResult<T, E>

source§

fn partial_cmp(&self, other: &RResult<T, E>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

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

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

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

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

§

type IsNonZeroType = False

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

const LAYOUT: &'static TypeLayout = _

The layout of the type provided by implementors.
source§

const ABI_CONSTS: AbiConsts = _

const-equivalents of the associated types.
source§

impl<T: Copy, E: Copy> Copy for RResult<T, E>

source§

impl<T: Eq, E: Eq> Eq for RResult<T, E>

source§

impl<T, E> StructuralEq for RResult<T, E>

source§

impl<T, E> StructuralPartialEq for RResult<T, E>

Auto Trait Implementations§

§

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

§

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§

source§

impl<T> AlignerFor<1> for T

§

type Aligner = AlignTo1<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<1024> for T

§

type Aligner = AlignTo1024<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<128> for T

§

type Aligner = AlignTo128<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<16> for T

§

type Aligner = AlignTo16<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<16384> for T

§

type Aligner = AlignTo16384<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<2> for T

§

type Aligner = AlignTo2<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<2048> for T

§

type Aligner = AlignTo2048<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<256> for T

§

type Aligner = AlignTo256<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<32> for T

§

type Aligner = AlignTo32<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<32768> for T

§

type Aligner = AlignTo32768<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<4> for T

§

type Aligner = AlignTo4<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<4096> for T

§

type Aligner = AlignTo4096<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<512> for T

§

type Aligner = AlignTo512<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<64> for T

§

type Aligner = AlignTo64<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<8> for T

§

type Aligner = AlignTo8<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> AlignerFor<8192> for T

§

type Aligner = AlignTo8192<T>

The AlignTo* type which aligns Self to ALIGNMENT.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<'a, T> RCowCompatibleRef<'a> for T
where T: Clone + 'a,

§

type RefC = &'a T

The (preferably) ffi-safe equivalent of &Self.
§

type ROwned = T

The owned version of Self::RefC.
source§

fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC

Converts a reference to an FFI-safe type
source§

fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T

Converts an FFI-safe type to a reference
source§

impl<S> ROExtAcc for S

source§

fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F

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

fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F

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

fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F

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

fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F

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

impl<S> ROExtOps<Aligned> for S

source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F

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

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Aligned>, right: &mut S)

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

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> F
where F: Copy,

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

impl<S> ROExtOps<Unaligned> for S

source§

fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F

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

fn f_swap<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, right: &mut S)

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

fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> F
where F: Copy,

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

impl<T> SelfOps for T
where T: ?Sized,

source§

fn eq_id(&self, other: &Self) -> bool

Compares the address of self with the address of other. Read more
source§

fn piped<F, U>(self, f: F) -> U
where F: FnOnce(Self) -> U, Self: Sized,

Emulates the pipeline operator, allowing method syntax in more places. Read more
source§

fn piped_ref<'a, F, U>(&'a self, f: F) -> U
where F: FnOnce(&'a Self) -> U,

The same as piped except that the function takes &Self Useful for functions that take &Self instead of Self. Read more
source§

fn piped_mut<'a, F, U>(&'a mut self, f: F) -> U
where F: FnOnce(&'a mut Self) -> U,

The same as piped, except that the function takes &mut Self. Useful for functions that take &mut Self instead of Self.
source§

fn mutated<F>(self, f: F) -> Self
where F: FnOnce(&mut Self), Self: Sized,

Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
source§

fn observe<F>(self, f: F) -> Self
where F: FnOnce(&Self), Self: Sized,

Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
source§

fn into_<T>(self) -> T
where Self: Into<T>,

Performs a conversion with Into. using the turbofish .into_::<_>() syntax. Read more
source§

fn as_ref_<T>(&self) -> &T
where Self: AsRef<T>, T: ?Sized,

Performs a reference to reference conversion with AsRef, using the turbofish .as_ref_::<_>() syntax. Read more
source§

fn as_mut_<T>(&mut self) -> &mut T
where Self: AsMut<T>, T: ?Sized,

Performs a mutable reference to mutable reference conversion with AsMut, using the turbofish .as_mut_::<_>() syntax. Read more
source§

fn drop_(self)
where Self: Sized,

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

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<This> TransmuteElement for This
where This: ?Sized,

source§

unsafe fn transmute_element<T>( self ) -> <Self as CanTransmuteElement<T>>::TransmutedPtr
where Self: CanTransmuteElement<T>,

Transmutes the element type of this pointer.. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> TypeIdentity for T
where T: ?Sized,

§

type Type = T

This is always Self.
source§

fn into_type(self) -> Self::Type
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
source§

fn as_type(&self) -> &Self::Type

Converts a reference back to the original type.
source§

fn as_type_mut(&mut self) -> &mut Self::Type

Converts a mutable reference back to the original type.
source§

fn into_type_box(self: Box<Self>) -> Box<Self::Type>

Converts a box back to the original type.
source§

fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>

Converts an Arc back to the original type. Read more
source§

fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>

Converts an Rc back to the original type. Read more
source§

fn from_type(this: Self::Type) -> Self
where Self: Sized, Self::Type: Sized,

Converts a value back to the original type.
source§

fn from_type_ref(this: &Self::Type) -> &Self

Converts a reference back to the original type.
source§

fn from_type_mut(this: &mut Self::Type) -> &mut Self

Converts a mutable reference back to the original type.
source§

fn from_type_box(this: Box<Self::Type>) -> Box<Self>

Converts a box back to the original type.
source§

fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>

Converts an Arc back to the original type.
source§

fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>

Converts an Rc back to the original type.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<This> ValidTag_Bounds for This
where This: Debug + Clone + PartialEq,