pub struct Res(/* private fields */);Expand description
An opaque result type for error handling without exposing error details.
This type is designed to prevent side-channel attacks by not revealing specific error information. It only indicates success or failure.
Implementations§
Source§impl Res
impl Res
Sourcepub fn check(&mut self, res: bool)
pub fn check(&mut self, res: bool)
Updates the result based on a boolean condition.
If res is false, this method will set the Res to an error state.
§Arguments
res- A boolean representing a condition to check.
Sourcepub fn ensure_1(&mut self, res: c_int)
pub fn ensure_1(&mut self, res: c_int)
Ensures that a C integer result is equal to 1.
Sets the Res to an error state if the input is not 1.
§Arguments
res- A C integer to check.
Sourcepub fn ensure_0(&mut self, res: c_int)
pub fn ensure_0(&mut self, res: c_int)
Ensures that a C integer result is equal to 0.
Sets the Res to an error state if the input is not 0.
§Arguments
res- A C integer to check.
Sourcepub fn ensure_pos(&mut self, res: c_int)
pub fn ensure_pos(&mut self, res: c_int)
Ensures that a C integer result is positive.
Sets the Res to an error state if the input is not positive.
§Arguments
res- A C integer to check.
Sourcepub fn ensure(&mut self, res: Self)
pub fn ensure(&mut self, res: Self)
Combines this Res with another Res.
The result will be OK only if both Res instances are OK.
§Arguments
res- AnotherResinstance to combine with this one.
Sourcepub fn unit_err<OK>(self, ok: OK) -> Result<OK, Unspecified>
pub fn unit_err<OK>(self, ok: OK) -> Result<OK, Unspecified>
Sourcepub fn unit_err_with<F, OK>(self, ok: F) -> Result<OK, Unspecified>where
F: FnOnce() -> OK,
pub fn unit_err_with<F, OK>(self, ok: F) -> Result<OK, Unspecified>where
F: FnOnce() -> OK,
Converts the Res into a Result<OK, Unspecified>, with a closure for the OK case.
§Warning
This method is not constant time and should be used carefully in security-sensitive contexts.
§When to Use
Use this method when the creation of the OK value depends on the result
being OK for safety reasons. The closure is only called if the Res is OK,
ensuring that any preconditions for the OK value’s creation are met.
§Arguments
ok- A closure that returns the value for theOkvariant if theResis OK.
§Returns
Ok(ok()) if the Res is OK, Err(Unspecified) otherwise.