CResult

Enum CResult 

Source
#[repr(u8)]
pub enum CResult<TOk, TErr> { Ok(TOk), Err(TErr), }
Expand description

This enum is essentially the same as the standard Result, except it is #[repr(C)] and thus safe to use a cross the ffi boundaries.

Note that the safety is guaranteed only for the enum itself, not for the data it holds. Meaning you still have to manually use #[repr(C)] on TOk and TErr for the inner data to be ffi safe.

It additionally provides const variants of Result methods.

Variants§

§

Ok(TOk)

§

Err(TErr)

Implementations§

Source§

impl<TOk, TErr> CResult<TOk, TErr>

Source

pub const fn is_ok(&self) -> bool

Returns true if the enum holds CResult::Ok, false otherwise.

Source

pub const fn is_err(&self) -> bool

Returns true if the enum holds CResult::Err, false otherwise.

Source

pub const fn unwrap(self) -> TOk

Unwraps currently stored CResult::Ok value.

§Panics

Only when self actually holds a CResult::Err value.

Source

pub const unsafe fn unwrap_unchecked(self) -> TOk

Unwraps currently stored CResult::Ok value.

§Safety

This function does not verify whether the stored value is actually CResult::Ok. The behaviour is undefined if it is not.

Source

pub const fn unwrap_err(self) -> TErr

Unwraps currently stored CResult::Err value.

§Panics

Only when self actually holds an CResult::Ok value.

Source

pub const unsafe fn unwrap_err_unchecked(self) -> TErr

Unwraps currently stored CResult::Err value.

§Safety

This function does not verify whether the stored value is actually CResult::Err. The behaviour is undefined if it is not.

Source

pub const fn into_result(self) -> Result<TOk, TErr>

Converts CResult into standard Result.

Source

pub const fn from_result(result: Result<TOk, TErr>) -> Self

Converts standard Result into CResult.

Trait Implementations§

Source§

impl<TOk: Debug, TErr: Debug> Debug for CResult<TOk, TErr>

Source§

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

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

impl<TOk, TErr> From<CResult<TOk, TErr>> for Result<TOk, TErr>

Source§

fn from(value: CResult<TOk, TErr>) -> Self

Converts to this type from the input type.
Source§

impl<TOk, TErr> From<Result<TOk, TErr>> for CResult<TOk, TErr>

Source§

fn from(value: Result<TOk, TErr>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<TOk, TErr> Freeze for CResult<TOk, TErr>
where TOk: Freeze, TErr: Freeze,

§

impl<TOk, TErr> RefUnwindSafe for CResult<TOk, TErr>
where TOk: RefUnwindSafe, TErr: RefUnwindSafe,

§

impl<TOk, TErr> Send for CResult<TOk, TErr>
where TOk: Send, TErr: Send,

§

impl<TOk, TErr> Sync for CResult<TOk, TErr>
where TOk: Sync, TErr: Sync,

§

impl<TOk, TErr> Unpin for CResult<TOk, TErr>
where TOk: Unpin, TErr: Unpin,

§

impl<TOk, TErr> UnwindSafe for CResult<TOk, TErr>
where TOk: UnwindSafe, TErr: UnwindSafe,

Blanket Implementations§

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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.