pub trait MessageAdapter<W: Workflow>:
Send
+ Sync
+ 'static {
// Required methods
fn accepts_format_version(&self, fv: &FormatVersion) -> bool;
fn adapt(
&self,
raw: &dyn Any,
fv: &FormatVersion,
) -> Result<W::Command, EngineError>;
}Expand description
Translates a parsed EDIFACT message into a domain command for workflow W.
Implement one MessageAdapter per (message type, format version range)
combination that your workflow needs to handle. An adapter that handles
multiple format versions via internal branching is also valid.
§Thread safety
Adapters must be Send + Sync + 'static because they are stored in an
AdapterRegistry that is shared across async tasks.
Required Methods§
Sourcefn accepts_format_version(&self, fv: &FormatVersion) -> bool
fn accepts_format_version(&self, fv: &FormatVersion) -> bool
Returns true when this adapter can translate messages formatted under
fv.
The AdapterRegistry calls this during validation to confirm that
every format version declared by the workflow’s
WorkflowVersionPolicy is covered.
Sourcefn adapt(
&self,
raw: &dyn Any,
fv: &FormatVersion,
) -> Result<W::Command, EngineError>
fn adapt( &self, raw: &dyn Any, fv: &FormatVersion, ) -> Result<W::Command, EngineError>
Translate a raw parsed message into a domain command.
fv is the format version detected from the wire message (e.g. from
EdiEnergyMessage::detect_release). Use it to select the correct
field mapping when the adapter handles multiple format versions.
§Errors
Return EngineError::Workflow when the message is structurally valid
but semantically inappropriate for this command (e.g. wrong PID).
Return EngineError::Deserialization when a required field is absent
or malformed.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".