Enum abi_stable::std_types::RResult
source · #[repr(u8)]pub enum RResult<T, E> {
ROk(T),
RErr(E),
}
Expand description
Ffi-safe equivalent of Result<T, E>
.
Variants§
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<M: RootModule> IntoRootModuleResult for RResult<M, RBoxError>
impl<M: RootModule> IntoRootModuleResult for RResult<M, RBoxError>
source§fn into_root_module_result(self) -> Result<M, RootModuleError>
fn into_root_module_result(self) -> Result<M, RootModuleError>
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§type IsNonZeroType = False
type IsNonZeroType = False
source§const LAYOUT: &'static TypeLayout = _
const LAYOUT: &'static TypeLayout = _
source§const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.impl<T: Copy, E: Copy> Copy for RResult<T, E>
impl<T: Eq, E: Eq> Eq for RResult<T, E>
impl<T, E> StructuralPartialEq for RResult<T, E>
Auto Trait Implementations§
impl<T, E> Freeze for RResult<T, E>
impl<T, E> RefUnwindSafe for RResult<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for RResult<T, E>
impl<T, E> Sync for RResult<T, E>
impl<T, E> Unpin for RResult<T, E>
impl<T, E> UnwindSafe for RResult<T, E>where
T: UnwindSafe,
E: UnwindSafe,
Blanket Implementations§
source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo*
type which aligns Self
to ALIGNMENT
.source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
impl<'a, T> RCowCompatibleRef<'a> for Twhere
T: Clone + 'a,
source§fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
fn as_c_ref(from: &'a T) -> <T as RCowCompatibleRef<'a>>::RefC
source§fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
fn as_rust_ref(from: <T as RCowCompatibleRef<'a>>::RefC) -> &'a T
source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset
. Read moresource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset
. Read moresource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset
. Read moresource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset
. Read moresource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset
) with value
,
returning the previous value of the field. Read moresource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read moresource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
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
fn mutated<F>(self, f: F) -> Self
source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more