Expand description
This library is inspired in the ensure and bail macros from anyhow. The difference is that it is not tied to anyhow’s types.
Many libraries have their own error types and using the anyhow’s ensure macro doesn’t work because it returns an anyhow error. This library intends to work with any type.
This library also provides the assure macro, that does the same but evaluates to a Result instead of returning. This is useful for using inside try blocks.
Macros§
- assure
- Ensures the condition is met. This evaluates to a
Result<(), ERROR>This macro is equivalent toif !cond { Err(error) } else { Ok(()) }. Example: - assure_
not - Ensures the condition is not met. This evaluates to a
Result<(), ERROR>This macro is equivalent toif cond { Err(error) } else { Ok(()) }. Example: - assure_
not_ or - Ensures the condition is not met or returns the value. This evaluates to a
Result<VALUE, ERROR>This macro is equivalent toif cond { Err(error) } else { Ok(value) }. Example: - assure_
or - Ensures the condition is met or returns the value. This evaluates to a
Result<VALUE, ERROR>This macro is equivalent toif !cond { Err(error) } else { Ok(value) }. Example: - bail
- Return early with an error.
This macro is equivalent to
return Err(error). Example: - ensure
- Return early with an error if the condition is false. This ensures the condition is met.
This macro is equivalent to
if !cond { return Err(error) }. Example: - ensure_
not - Return early with an error if the condition is true. This ensures the condition is not met.
This macro is equivalent to
if cond { return Err(error) }. Example: