Skip to main content

display

Attribute Macro display 

Source
#[display]
Expand description

Ergonomically implement Display for enums

ยงExample

use displaystr::display;

#[display]
pub enum DataStoreError {
    Disconnect(std::io::Error) = "data store disconnected",
    InvalidHeader {
        expected: String,
        found: String,
    } = "invalid header (expected {expected:?}, found {found:?})",
}

The above expands to this:

use displaystr::display;

pub enum DataStoreError {
    Disconnect(std::io::Error),
    InvalidHeader {
        expected: String,
        found: String,
    },
}

impl ::core::fmt::Display for DataStoreError {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::Disconnect(_0) => {
                f.write_fmt(format_args!("data store disconnected"))
            }
            Self::InvalidHeader { expected, found } => {
                f.write_fmt(format_args!("invalid header (expected {expected}, found {found})"))
            }
        }
    }
}

For more information, see the crate-level documentation