Skip to main content

ocpi_enum

Macro ocpi_enum 

Source
macro_rules! ocpi_enum {
    (
        $(#[$meta:meta])*
        $vis:vis enum $name:ident {
            $(
                $(#[$vmeta:meta])*
                $variant:ident = $wire:literal
            ),* $(,)?
        }
    ) => { ... };
}
Expand description

Defines a closed OCPI enum: a fixed set of strings, where anything else is an error.

use ocpi_kit::ocpi_enum;

ocpi_enum! {
    /// The format of the connector, whether it is a socket or a plug.
    ///
    /// Spec: 2.3.0 §mod_locations_connectorformat_enum
    pub enum ConnectorFormat {
        /// The connector is a socket; the EV user needs to bring a fitting plug.
        Socket = "SOCKET",
        /// The connector is an attached cable.
        Cable = "CABLE",
    }
}

assert_eq!(ConnectorFormat::Socket.as_str(), "SOCKET");
assert!("SCREW".parse::<ConnectorFormat>().is_err());

Attributes that document the enum — #[cfg_attr(docsrs, doc(cfg(…)))] above all — go inside the invocation, on the pub enum line, so they land on the item this expands to. On the invocation itself they document nothing, and rustdoc refuses them. A #[cfg] is the exception: it belongs outside, where it gates the whole expansion rather than the enum alone.