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§
ROk(PrefixRef<ErasedPrefix>)
RErr(RootModuleError)
Implementations
Source§impl<T, E> RResult<T, E>
impl<T, E> RResult<T, E>
Sourcepub const fn as_ref(&self) -> RResult<&T, &E>
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));
Sourcepub fn as_mut(&mut self) -> RResult<&mut T, &mut E>
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));
Sourcepub const fn is_rok(&self) -> bool
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);
Sourcepub const fn is_ok(&self) -> bool
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);
Sourcepub const fn is_rerr(&self) -> bool
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);
Sourcepub const fn is_err(&self) -> bool
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);
Sourcepub fn into_result(self) -> Result<T, E>
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));
Sourcepub fn map<U, F>(self, op: F) -> RResult<U, E>where
F: FnOnce(T) -> U,
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));
Sourcepub fn map_err<F, O>(self, op: O) -> RResult<T, F>where
O: FnOnce(E) -> F,
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));
Sourcepub fn map_or_else<U, M, F>(self, with_err: F, with_ok: M) -> U
pub fn map_or_else<U, M, F>(self, with_err: F, with_ok: M) -> 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);
Sourcepub fn and_then<U, F>(self, op: F) -> RResult<U, E>
pub fn and_then<U, F>(self, op: F) -> 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),
);
Sourcepub fn or_else<F, O>(self, op: O) -> RResult<T, F>
pub fn or_else<F, O>(self, op: O) -> 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)
);
Sourcepub fn unwrap_err(self) -> Ewhere
T: Debug,
pub fn unwrap_err(self) -> Ewhere
T: Debug,
Sourcepub fn expect_err(self, message: &str) -> Ewhere
T: Debug,
pub fn expect_err(self, message: &str) -> Ewhere
T: Debug,
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");
Sourcepub fn unwrap_or(self, optb: T) -> T
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);
Sourcepub fn unwrap_or_else<F>(self, op: F) -> Twhere
F: FnOnce(E) -> T,
pub fn unwrap_or_else<F>(self, op: F) -> Twhere
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);
Sourcepub fn unwrap_or_default(self) -> Twhere
T: Default,
pub fn unwrap_or_default(self) -> Twhere
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);
Trait Implementations
Source§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>,
Source§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>,
Source§impl<T, E> GetStaticEquivalent_ for RResult<T, E>where
T: __StableAbi,
E: __StableAbi,
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>
type StaticEquivalent = _static_RResult<<T as GetStaticEquivalent_>::StaticEquivalent, <E as GetStaticEquivalent_>::StaticEquivalent>
'static
equivalent of Self
Source§impl<T, E> IntoReprRust for RResult<T, E>
impl<T, E> IntoReprRust for RResult<T, E>
Source§impl<T: Ord, E: Ord> Ord for RResult<T, E>
impl<T: Ord, E: Ord> Ord for RResult<T, E>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd, E: PartialOrd> PartialOrd for RResult<T, E>
impl<T: PartialOrd, E: PartialOrd> PartialOrd for RResult<T, E>
Source§impl<T, E> StableAbi for RResult<T, E>where
T: __StableAbi,
E: __StableAbi,
impl<T, E> StableAbi for RResult<T, E>where
T: __StableAbi,
E: __StableAbi,
Source§const LAYOUT: &'static TypeLayout = _
const LAYOUT: &'static TypeLayout = _
Source§type IsNonZeroType = False
type IsNonZeroType = False
Source§const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.