#[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 across the
ffi boundaries.
It additionally provides const variants of Result methods.
Also note that the layout is fixed, and unlike standard Result,
it doesn’t depend on TOk, TErr.
Variants§
Implementations§
Source§impl<TOk, TErr> CResult<TOk, TErr>
impl<TOk, TErr> CResult<TOk, TErr>
Sourcepub const fn is_ok(&self) -> bool
pub const fn is_ok(&self) -> bool
Returns true if the enum holds CResult::Ok,
false otherwise.
Sourcepub const fn is_err(&self) -> bool
pub const fn is_err(&self) -> bool
Returns true if the enum holds CResult::Err,
false otherwise.
Sourcepub fn expect(self, message: &str) -> TOk
pub fn expect(self, message: &str) -> TOk
Unwraps currently stored CResult::Ok value.
§Panics
Only when self actually holds a CResult::Err value.
Sourcepub const fn unwrap(self) -> TOk
pub const fn unwrap(self) -> TOk
Unwraps currently stored CResult::Ok value.
§Panics
Only when self actually holds a CResult::Err value.
Sourcepub const unsafe fn unwrap_unchecked(self) -> TOk
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.
Sourcepub const fn unwrap_err(self) -> TErr
pub const fn unwrap_err(self) -> TErr
Unwraps currently stored CResult::Err value.
§Panics
Only when self actually holds an CResult::Ok value.
Sourcepub const unsafe fn unwrap_err_unchecked(self) -> TErr
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.
Sourcepub const fn into_result(self) -> Result<TOk, TErr>
pub const fn into_result(self) -> Result<TOk, TErr>
Converts CResult into standard Result.
Sourcepub const fn from_result(result: Result<TOk, TErr>) -> Self
pub const fn from_result(result: Result<TOk, TErr>) -> Self
Converts standard Result into CResult.