abi_stable::library

Type Alias RootModuleResult

Source
pub type RootModuleResult = RResult<PrefixRef<ErasedPrefix>, RootModuleError>;
Expand description

The return type of the function that the #[export_root_module] attribute outputs.

Aliased Type§

enum RootModuleResult {
    ROk(PrefixRef<ErasedPrefix>),
    RErr(RootModuleError),
}

Variants§

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

Source§

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>

Source§

type ReprRust = Result<T, E>

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

fn into_rust(self) -> Self::ReprRust

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,

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

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

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

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

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,

Source§

const LAYOUT: &'static TypeLayout = _

The layout of the type provided by implementors.
Source§

type IsNonZeroType = False

Whether this type has a single invalid bit-pattern. Read more
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> StructuralPartialEq for RResult<T, E>