edifact_types/d00b/mod.rs
1use crate::util::Parser;
2use edifact_types_macros::DisplayEdifact;
3use nom::Parser as _;
4use nom::{combinator::opt, IResult};
5use serde::{Deserialize, Serialize};
6use std::fmt;
7
8const VERSION: &str = "D00B";
9
10mod element;
11mod message;
12mod segment;
13mod types;
14
15// Re-Export on root level to keep compatibility
16pub use element::*;
17pub use message::coparn::*;
18pub use message::coprar::*;
19pub use message::coreor::*;
20pub use message::iftmbf::*;
21pub use message::iftmcs::*;
22pub use message::iftmin::*;
23pub use message::iftsta::*;
24pub use segment::*;
25pub use types::*;
26
27#[cfg(test)]
28mod test_segment;
29
30/// from: [official info](https://unece.org/fileadmin/DAM/trade/edifact/untdid/d422_s.htm)
31/// 6.1 Interchange structure
32///
33/// The Service String Advice, UNA, and the service segments UNB
34/// to UNZ shall appear in the below stated order in an
35/// interchange. There may be several functional groups or
36/// messages within an interchange and several messages in a
37/// functional group. A message consists of segments. The
38/// structures for segments and for data elements therein are
39/// shown in 6.2 and 6.3. The contents of the service segments
40/// are shown annex B. See also figure 1.
41///
42/// An interchange consists of:
43///
44/// x | x | x | x | Name | Abbr. | Req.
45/// --- | --- | --- | --- | --- | --- | ---
46/// o | o | o | o | Service String Advice | UNA | Conditional
47/// _ | _ | _ | _ | Interchange Header | UNB | Mandatory
48/// \| | _ | _ | _ | Functional Group Header | UNG | Conditional
49/// \| | \| | _ | _ | Message Header | UNH | Mandatory
50/// \| | \| | \| | | User Data Segments | | As required
51/// \| | \| | \| | _ | Message Trailer | UNT | Mandatory
52/// \| | \| | _ | _ | Functional Group Trailer | UNE | Conditional
53/// \| | _ | _ | _ | Interchange Trailer | UNZ | Mandatory
54///
55/// In addition to the above service segments, the service
56/// segment UNS can, when required, be used to divide a message
57/// into sections. See annex B (NOT IMPLEMENTED).
58#[derive(Serialize, Deserialize, Clone, Default, Debug, PartialEq, Eq, DisplayEdifact)]
59pub struct Interchange<T>
60where
61 T: std::fmt::Display,
62{
63 pub una: Option<UNA>,
64 pub unb: UNB,
65 pub segment: T,
66 pub unz: UNZ,
67}
68
69impl<'a, T: Default + Parser<&'a str, T, nom::error::Error<&'a str>> + std::fmt::Display>
70 Parser<&'a str, Interchange<T>, nom::error::Error<&'a str>> for Interchange<T>
71{
72 fn parse(input: &'a str) -> IResult<&'a str, Interchange<T>> {
73 let mut output = Interchange::default();
74 let (input, obj) = opt(UNA::parse).parse(input)?;
75 output.una = obj;
76 let (input, obj) = UNB::parse(input)?;
77 output.unb = obj;
78 let (input, t_obj) = T::parse(input)?;
79 output.segment = t_obj;
80 let (input, obj) = UNZ::parse(input)?;
81 output.unz = obj;
82 Ok((input, output))
83 }
84}