Skip to main content

Mapper

Struct Mapper 

Source
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

Source

pub fn from_data_dir(data_dir: DataDir) -> Result<Self, MapperError>

Create a new Mapper from a DataDir configuration.

Any format versions marked as eager are loaded immediately. All others are loaded lazily on first access.

Source

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.

Source

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.

Source

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).

Source

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));
Source

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.

Source

pub fn loaded_format_versions(&self) -> Vec<String>

List all format versions currently loaded in memory.

Source

pub fn variants(&self, fv: &str) -> Result<Vec<String>, MapperError>

List all variants available in a format version’s bundle.

Loads the bundle if not already loaded.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.