[][src]Crate bail_out

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.

Macros

bail

Return early with an error. This macro is equivalent to return Err(error). Example:

ensure

Ensures the condition is met. This evaluates to a Result<(), ERROR> This macro is equivalent to if !cond { Err(error) } else { Ok(()) }. Example:

ensure_bail

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_bail_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:

ensure_not

Ensures the condition is not met. This evaluates to a Result<(), ERROR> This macro is equivalent to if cond { Err(error) } else { Ok(()) }. Example:

ensure_not_or

Ensures the condition is not met or returns the value. This evaluates to a Result<VALUE, ERROR> This macro is equivalent to if cond { Err(error) } else { Ok(value) }. Example:

ensure_or

Ensures the condition is met or returns the value. This evaluates to a Result<VALUE, ERROR> This macro is equivalent to if !cond { Err(error) } else { Ok(value) }. Example: