Macro option_like

Source
macro_rules! option_like {
    (
        $(#[$meta:meta])*
        $vis:vis enum $name:ident<T> {
            $(#[$some_meta:meta])*
            $some:ident(T),
            $(#[$none_meta:meta])*
            $none:ident,
        }

        is_some => $is_some:ident
        is_none => $is_none:ident
    ) => { ... };
}
Expand description

Creates a new enum type that behaves like Rust’s Option<T> but with custom names.

This macro allows you to create your own Option-like enum with customized names for the variants and boolean test methods, while providing automatic conversions to and from the standard Option type.

§Parameters

  • $(#[$meta:meta])*: Optional attributes to apply to the enum (e.g., #[derive(...)])
  • $vis: Visibility of the enum (e.g., pub)
  • $name: Name of the enum (e.g., Cached)
  • $some: Name of the variant that holds a value (e.g., Hit)
  • $none: Name of the empty variant (e.g., Miss)
  • is_some => $is_some: Name of the method that checks if the enum holds a value (e.g., is_hit)
  • is_none => $is_none: Name of the method that checks if the enum is empty (e.g., is_miss)