pub struct DirectoryValidator { /* private fields */ }Expand description
Shared validator implementation that is configured per UN/EDIFACT directory release.
§Scope and limitations
DirectoryValidator validates individual segment content (element counts,
component counts, code-list values, and conditional rules) and checks that
every mandatory segment type is present at least once. It does not
validate segment sequence or repetition cardinality — i.e., it cannot
tell you that a BGM segment appears more than once, or that a RFF group
appears in the wrong position. Full sequence validation requires a
state-machine per message type (UN/EDIFACT Segment Tables) which is outside
the scope of this implementation.
Implementations§
Source§impl DirectoryValidator
impl DirectoryValidator
Sourcepub fn new(
directory_id: &'static str,
segment_lookup: fn(&str) -> Option<&'static SegmentDefinition>,
is_code_valid: fn(&str, &str) -> bool,
suggest_code: fn(&str, &str) -> Option<&'static str>,
expected_components: fn(&str, usize) -> Option<u8>,
additional_structure_rule: Option<fn(&Segment<'_>) -> Result<(), EdifactError>>,
) -> Self
pub fn new( directory_id: &'static str, segment_lookup: fn(&str) -> Option<&'static SegmentDefinition>, is_code_valid: fn(&str, &str) -> bool, suggest_code: fn(&str, &str) -> Option<&'static str>, expected_components: fn(&str, usize) -> Option<u8>, additional_structure_rule: Option<fn(&Segment<'_>) -> Result<(), EdifactError>>, ) -> Self
Create a validator for a specific directory release with injected lookup/check hooks.
Sourcepub fn from_definitions(definitions: &'static [SegmentDefinition]) -> Self
pub fn from_definitions(definitions: &'static [SegmentDefinition]) -> Self
Create a validator from a static slice of SegmentDefinitions.
This is the preferred constructor when code-generating directory data as
a static array: no manual fn-pointer boilerplate is required.
Code-list checks are disabled by default (the built-in is_code_valid
always returns true). Call with_code_list_rules
to register directory-specific rules that actually validate code values.
§Example
static MY_SEGMENTS: &[SegmentDefinition] = &[ /* … */ ];
let validator = DirectoryValidator::from_definitions(MY_SEGMENTS)
.with_code_list_rules(my_code_list_rules);Sourcepub fn from_owned_definitions(definitions: Vec<OwnedSegmentDef>) -> Self
pub fn from_owned_definitions(definitions: Vec<OwnedSegmentDef>) -> Self
Create a validator from a runtime-owned collection of segment definitions.
Use this (or DirectoryValidatorBuilder) when segment definitions are
loaded from an external source at startup (JSON, database, YAML, …) rather
than being known at compile time.
Code-list checks are disabled by default; enable them by chaining
with_code_list_rules and setting
is_code_valid via a custom new call or by subclassing
the builder.
§Example
let defs = vec![
OwnedSegmentDef::new(
"BGM".to_owned(),
"Beginning of message".to_owned(),
vec![OwnedElementRef::new(1, "C002".to_owned(), Status::Mandatory, 1)],
),
];
let validator = DirectoryValidator::from_owned_definitions(defs)
.with_directory_id("runtime-profile");Sourcepub fn with_directory_id(self, id: impl Into<String>) -> Self
pub fn with_directory_id(self, id: impl Into<String>) -> Self
Set the directory identifier string (used in error messages).
Sourcepub fn with_code_list_rules(
self,
f: impl Fn(&str) -> &'static [(usize, usize, &'static str)] + Send + Sync + 'static,
) -> Self
pub fn with_code_list_rules( self, f: impl Fn(&str) -> &'static [(usize, usize, &'static str)] + Send + Sync + 'static, ) -> Self
Override the code-list rules function.
Directories can supply a directory-specific implementation that extends or
replaces the base rules from base_code_list_rules.
Sourcepub fn structure_only(self) -> Self
pub fn structure_only(self) -> Self
Enable only structure checks and disable code-list checks.
Sourcepub fn code_list_only(self) -> Self
pub fn code_list_only(self) -> Self
Enable only code-list checks and disable structure checks.
Configure whether unknown segment tags should be rejected.
Sourcepub fn with_required_segments(
self,
f: impl Fn(&str) -> &'static [&'static str] + Send + Sync + 'static,
) -> Self
pub fn with_required_segments( self, f: impl Fn(&str) -> &'static [&'static str] + Send + Sync + 'static, ) -> Self
Override the required-segments mapping used for structural validation.
The supplied function receives an EDIFACT message type string (e.g. "ORDERS")
and must return a 'static slice of segment tags that are mandatory for that
type. The tags are checked both for presence and for canonical ordering
within the message.
§Example
fn my_required_segments(msg_type: &str) -> &'static [&'static str] {
match msg_type {
"DESADV" => &["UNH", "BGM", "SHP", "UNT"],
"INVOIC" => &["UNH", "BGM", "MOA", "UNT"],
_ => &["UNH", "UNT"],
}
}
let validator = DirectoryValidator::from_definitions(DEFS)
.with_required_segments(my_required_segments);Trait Implementations§
Source§impl Clone for DirectoryValidator
impl Clone for DirectoryValidator
Source§fn clone(&self) -> DirectoryValidator
fn clone(&self) -> DirectoryValidator
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DirectoryValidator
impl Debug for DirectoryValidator
Source§impl Validator for DirectoryValidator
impl Validator for DirectoryValidator
Source§fn set_message_type(&mut self, message_type: Option<&str>)
fn set_message_type(&mut self, message_type: Option<&str>)
Source§fn validate_batch(
&self,
segments: &[Segment<'_>],
report: &mut ValidationReport,
_context: &ValidationRuleContext<'_>,
)
fn validate_batch( &self, segments: &[Segment<'_>], report: &mut ValidationReport, _context: &ValidationRuleContext<'_>, )
report. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for DirectoryValidator
impl !UnwindSafe for DirectoryValidator
impl Freeze for DirectoryValidator
impl Send for DirectoryValidator
impl Sync for DirectoryValidator
impl Unpin for DirectoryValidator
impl UnsafeUnpin for DirectoryValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more