pub struct RawSegment<'a> {
pub id: &'a str,
pub elements: Vec<Vec<&'a str>>,
pub position: SegmentPosition,
}Expand description
A parsed EDIFACT segment that borrows from the input buffer.
Zero-copy design: all string data references the original input, avoiding allocations during the parsing hot path.
§Structure
An EDIFACT segment like NAD+Z04+9900123000002:500 has:
id:"NAD"elements[0]:["Z04"](simple element)elements[1]:["9900123000002", "500"](composite element with 2 components)
Fields§
§id: &'a strSegment identifier (e.g., “NAD”, “LOC”, “DTM”).
elements: Vec<Vec<&'a str>>Elements, where each element is a vector of component strings.
elements[i][j] = component j of element i.
position: SegmentPositionPosition metadata for this segment.
Implementations§
Source§impl<'a> RawSegment<'a>
impl<'a> RawSegment<'a>
Sourcepub fn new(
id: &'a str,
elements: Vec<Vec<&'a str>>,
position: SegmentPosition,
) -> Self
pub fn new( id: &'a str, elements: Vec<Vec<&'a str>>, position: SegmentPosition, ) -> Self
Creates a new RawSegment.
Sourcepub fn element_count(&self) -> usize
pub fn element_count(&self) -> usize
Returns the number of elements (excluding the segment ID).
Sourcepub fn get_element(&self, index: usize) -> &str
pub fn get_element(&self, index: usize) -> &str
Gets the first component of element at index, or empty string if missing.
This is a convenience method for accessing simple (non-composite) elements.
Sourcepub fn get_component(
&self,
element_index: usize,
component_index: usize,
) -> &str
pub fn get_component( &self, element_index: usize, component_index: usize, ) -> &str
Gets a specific component within an element, or empty string if missing.
element_index is the 0-based element position.
component_index is the 0-based component position within that element.
Sourcepub fn get_components(&self, element_index: usize) -> &[&'a str]
pub fn get_components(&self, element_index: usize) -> &[&'a str]
Returns all components of element at index, or empty slice if missing.
Sourcepub fn is(&self, segment_id: &str) -> bool
pub fn is(&self, segment_id: &str) -> bool
Checks if the segment has the given ID (case-insensitive).
Sourcepub fn to_raw_string(&self, delimiters: &EdifactDelimiters) -> String
pub fn to_raw_string(&self, delimiters: &EdifactDelimiters) -> String
Reconstruct the raw segment string (without terminator) using the given delimiters.
This produces ID+elem1:comp1:comp2+elem2 format (without the trailing terminator).
Trait Implementations§
Source§impl<'a> Clone for RawSegment<'a>
impl<'a> Clone for RawSegment<'a>
Source§fn clone(&self) -> RawSegment<'a>
fn clone(&self) -> RawSegment<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more