zugferd_code_lists/zugferd_2_3_3/
linereason.rs1#![allow(non_camel_case_types)]
2
3#[cfg_attr(feature = "specta", derive(specta::Type))]
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)]
6pub enum LineReason {
7 RegularItemPositionStandardCase,
9 SubtotalOrGroup,
11 ForInformationOnly,
13}
14
15impl std::fmt::Display for LineReason {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 write!(f, "{}", <Self as crate::Code>::code(*self))
18 }
19}
20
21impl std::str::FromStr for LineReason {
22 type Err = crate::ParseError<Self>;
23 fn from_str(s: &str) -> Result<Self, Self::Err> {
24 <Self as crate::FromCode>::from_code(s)
25 .ok_or_else(|| crate::ParseError::<Self>::new(s.to_owned()))
26 }
27}
28
29impl crate::Code for LineReason {
30 fn code(self) -> &'static str {
31 match self {
32 LineReason::RegularItemPositionStandardCase => "DETAIL",
33 LineReason::SubtotalOrGroup => "GROUP",
34 LineReason::ForInformationOnly => "INFORMATION",
35 }
36 }
37}
38
39impl crate::Description for LineReason {
40 fn description(self) -> &'static str {
41 match self {
42 LineReason::RegularItemPositionStandardCase => "Regular item position (standard case)",
43 LineReason::SubtotalOrGroup => "Subtotal or group",
44 LineReason::ForInformationOnly => "For information only",
45 }
46 }
47}
48
49impl crate::FromCode for LineReason {
50 fn from_code(code: &str) -> Option<Self>
51 where
52 Self: Sized,
53 {
54 match code {
55 "DETAIL" => Some(LineReason::RegularItemPositionStandardCase),
56 "GROUP" => Some(LineReason::SubtotalOrGroup),
57 "INFORMATION" => Some(LineReason::ForInformationOnly),
58 _ => None,
59 }
60 }
61}