Skip to main content

SegmentLayout

Trait SegmentLayout 

Source
pub trait SegmentLayout {
    // Required methods
    fn layout_tag(&self) -> &str;
    fn resolve_code(
        &self,
        data_element: &str,
    ) -> Result<ElementPath, EdifactError>;
}
Expand description

Directory metadata that maps UN/EDIFACT data element identifiers to positions.

Implemented by SegmentDefinition (compile-time tables) and OwnedSegmentDef (runtime-loaded definitions), so the same code-addressed accessors work against either source.

§Example

use edifact_rs::{ElementRef, SegmentDefinition, SegmentLayout, Status};

static BGM_ELEMENTS: &[ElementRef] = &[
    ElementRef::new(1, "C002", Status::Conditional, 1),
    ElementRef::new(2, "C106", Status::Conditional, 1),
    ElementRef::new(3, "1225", Status::Conditional, 1),
];
static BGM: SegmentDefinition =
    SegmentDefinition::new("BGM", "Beginning of message", BGM_ELEMENTS);

let path = BGM.resolve_code("1225")?;
assert_eq!(path.element, 2);
assert!(BGM.resolve_code("9999").is_err());

Required Methods§

Source

fn layout_tag(&self) -> &str

The segment tag this layout describes (e.g. "NAD").

Source

fn resolve_code(&self, data_element: &str) -> Result<ElementPath, EdifactError>

Resolve a UN/EDIFACT data element identifier to a position.

§Errors

Returns EdifactError::UnknownDataElement when the identifier does not appear in this definition, and EdifactError::AmbiguousDataElement when it appears at more than one position.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§