Skip to main content

error

Macro error 

Source
macro_rules! error {
    ($code:expr) => { ... };
    ($code:expr, $msg:literal) => { ... };
    ($code:expr, $fmt:literal, $($args:expr),+ $(,)?) => { ... };
}
Expand description

Creates an Error with the specified ErrorCode and optional formatted message.

This macro provides a convenient and efficient way to construct Error instances with compile-time optimizations and meaningful default messages.

§Arguments

  • $code - An ErrorCode variant that categorizes the error type
  • $msg - (Optional) A string literal for static messages
  • $fmt - (Optional) A format string literal with {} placeholders
  • $args - (Optional) Arguments corresponding to format placeholders

§See Also

  • format! - For understanding format string syntax
  • Error::new - The underlying constructor being called
  • std::fmt - For advanced formatting options