pub struct Mapper { /* private fields */ }Expand description
High-level facade for EDIFACT-to-BO4E conversion.
Wraps DataBundle loading with lazy/eager initialization, and provides
convenient accessors for ConversionService and MappingEngine instances.
§Example
use edifact_mapper::{DataDir, Mapper};
let mapper = Mapper::from_data_dir(
DataDir::path("/opt/edifact/data").eager(&["FV2504"])
)?;
let cs = mapper.conversion_service("FV2504", "UTILMD_Strom")?;
let engine = mapper.engine("FV2504", "UTILMD_Strom", "55001")?;Implementations§
Source§impl Mapper
impl Mapper
Sourcepub fn from_data_dir(data_dir: DataDir) -> Result<Self, MapperError>
pub fn from_data_dir(data_dir: DataDir) -> Result<Self, MapperError>
Sourcepub fn conversion_service(
&self,
fv: &str,
variant: &str,
) -> Result<ConversionService, MapperError>
pub fn conversion_service( &self, fv: &str, variant: &str, ) -> Result<ConversionService, MapperError>
Get a ConversionService for the given format version and variant.
The service can tokenize EDIFACT input and assemble it into a MIG tree.
Sourcepub fn engine(
&self,
fv: &str,
variant: &str,
pid: &str,
) -> Result<MappingEngine, MapperError>
pub fn engine( &self, fv: &str, variant: &str, pid: &str, ) -> Result<MappingEngine, MapperError>
Get a MappingEngine for a specific PID within a format version and variant.
The engine can convert between assembled MIG trees and BO4E JSON.
Sourcepub fn validate_pid(
&self,
json: &Value,
fv: &str,
variant: &str,
pid: &str,
) -> Result<Vec<PidValidationError>, MapperError>
pub fn validate_pid( &self, json: &Value, fv: &str, variant: &str, pid: &str, ) -> Result<Vec<PidValidationError>, MapperError>
Validate a BO4E JSON object against PID requirements.
Returns a list of validation errors. Empty list = valid.
The json should be the transaction-level stammdaten (the entity map).
Sourcepub fn validate_pid_struct(
&self,
value: &impl Serialize,
fv: &str,
variant: &str,
pid: &str,
) -> Result<Vec<PidValidationError>, MapperError>
pub fn validate_pid_struct( &self, value: &impl Serialize, fv: &str, variant: &str, pid: &str, ) -> Result<Vec<PidValidationError>, MapperError>
Validate a typed BO4E struct against PID requirements.
Convenience wrapper that serializes the struct to JSON first.
Works with any Pid*Interchange or Pid*MessageStammdaten type.
§Example
let interchange = build_55001_interchange();
let errors = mapper.validate_pid_struct(&interchange, "FV2504", "UTILMD_Strom", "55001")?;
assert!(errors.is_empty(), "Errors:\n{}", ValidationReport(errors));Sourcepub fn validate_pid_with_conditions(
&self,
json: &Value,
fv: &str,
variant: &str,
pid: &str,
) -> Result<Vec<PidValidationError>, MapperError>
pub fn validate_pid_with_conditions( &self, json: &Value, fv: &str, variant: &str, pid: &str, ) -> Result<Vec<PidValidationError>, MapperError>
Validate with AHB condition awareness.
Reverse-maps the JSON to EDIFACT segments, evaluates AHB conditions, and reports fields as required/optional based on the actual data present.
Falls back to basic validation (without conditions) if no condition evaluator is available for the given variant/format version combination.
Sourcepub fn loaded_format_versions(&self) -> Vec<String>
pub fn loaded_format_versions(&self) -> Vec<String>
List all format versions currently loaded in memory.