micro_http/utils.rs
1//! Utility macros and functions for the HTTP crate.
2//!
3//! This module provides helper macros and functions that are used internally
4//! by the HTTP crate implementation.
5
6/// A macro for early returns with an error if a condition is not met.
7///
8/// This is similar to the `assert!` macro, but returns an error instead of panicking.
9/// It's useful for validation checks where you want to return early with an error
10/// if some condition is not satisfied.
11///
12/// # Arguments
13///
14/// * `$predicate` - A boolean expression that should evaluate to true
15/// * `$error` - The error value to return if the predicate is false
16///
17/// ```
18macro_rules! ensure {
19 ($predicate:expr, $error:expr) => {
20 if !$predicate {
21 return Err($error);
22 }
23 };
24}
25
26pub(crate) use ensure;