zugferd-code-lists 0.1.19

ZUGFeRD code lists, e.g. languages enum, currencies enum, countries enum, etc.
Documentation
#![allow(non_camel_case_types)]

#[cfg_attr(feature = "specta", derive(specta::Type))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
pub enum LineReason {
    /// Regular item position (standard case)
    RegularItemPositionStandardCase,
    /// Subtotal or group
    SubtotalOrGroup,
    /// For information only
    ForInformationOnly,
}

impl std::fmt::Display for LineReason {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", <Self as crate::Code>::code(*self))
    }
}

impl std::str::FromStr for LineReason {
    type Err = crate::ParseError<Self>;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        <Self as crate::FromCode>::from_code(s)
            .ok_or_else(|| crate::ParseError::<Self>::new(s.to_owned()))
    }
}

impl crate::Code for LineReason {
    fn code(self) -> &'static str {
        match self {
            LineReason::RegularItemPositionStandardCase => "DETAIL",
            LineReason::SubtotalOrGroup => "GROUP",
            LineReason::ForInformationOnly => "INFORMATION",
        }
    }
}

impl crate::Description for LineReason {
    fn description(self) -> &'static str {
        match self {
            LineReason::RegularItemPositionStandardCase => "Regular item position (standard case)",
            LineReason::SubtotalOrGroup => "Subtotal or group",
            LineReason::ForInformationOnly => "For information only",
        }
    }
}

impl crate::FromCode for LineReason {
    fn from_code(code: &str) -> Option<Self>
    where
        Self: Sized,
    {
        match code {
            "DETAIL" => Some(LineReason::RegularItemPositionStandardCase),
            "GROUP" => Some(LineReason::SubtotalOrGroup),
            "INFORMATION" => Some(LineReason::ForInformationOnly),
            _ => None,
        }
    }
}