Skip to main content

PidRouter

Struct PidRouter 

Source
pub struct PidRouter { /* private fields */ }
Expand description

A static mapping from Prüfidentifikator (PID) values to workflow names.

Register all PIDs your platform handles before starting the engine. At runtime, call route to look up the workflow name for an inbound PID.

The workflow name matches WorkflowId::name — use it to select the correct Workflow implementation in your message dispatcher.

§Mutability contract

PidRouter exposes a &mut self API for registrations (register). In the engine this mutability is exercised only during EngineBuilder::build — after that the router is owned by EngineContext and only shared references are available at runtime. There is no way to mutate the router from an async dispatch handler.

Duplicate registrations silently replace the previous mapping; the last call wins. Use cargo xtask validate-pruefids to detect PID conflicts between modules before they reach production.

§Building a complete router

In your main or integration module, register every PID that the platform must handle. PIDs not registered will return None from route, causing the dispatcher to dead-letter the message cleanly.

use mako_engine::pid_router::PidRouter;

fn build_router() -> PidRouter {
    let mut r = PidRouter::new();
    // GPKE Lieferantenwechsel (BK6-22-024) — UTILMD
    r.register(55001, "GpkeSupplierChange");
    r.register(55002, "GpkeSupplierChange");
    r.register(55003, "GpkeSupplierChange");
    r.register(55004, "GpkeSupplierChange");
    r
}

Implementations§

Source§

impl PidRouter

Source

pub fn new() -> Self

Create an empty router.

Source

pub fn register(&mut self, pid: u32, workflow_name: impl Into<Box<str>>)

Register pid as routing to workflow_name.

If pid was already registered, the previous mapping is silently replaced. Call this only at build time (via EngineModule::register_pids); the method is &mut self to prevent accidental runtime mutation once the router is sealed inside EngineContext.

Accepts any string — &'static str, String, or Box<str>.

For conflict-detected registration (preferred in multi-module builds), use register_with_module instead.

Source

pub fn register_with_module( &mut self, pid: u32, workflow_name: impl Into<Box<str>>, module: &str, )

Register pidworkflow_name with module-attribution conflict detection.

§Panics

Panics at build time (before the engine starts) if pid is already registered to a different workflow name by a different module. Two modules registering the same PID to the same workflow are silently accepted (idempotent).

Use DeploymentRoles to prevent two modules from registering the same PID when only one role is active:

// Both GPKE (NB role) and WiM (nMSB role) register 19001 → different workflows.
// Set explicit roles so only one module's conditional block fires:
use mako_engine::marktrolle::{DeploymentRoles, Marktrolle};
let roles = DeploymentRoles::from_roles([Marktrolle::Nb]);
// Now only GPKE registers 19001 → "gpke-konfiguration".
Source

pub fn register_with_sparte( &mut self, pid: u32, sparte: Sparte, workflow_name: impl Into<Box<str>>, )

Register pidworkflow_name for a specific commodity (Sparte).

Use this for PIDs that map to different workflows depending on whether the message concerns electricity (Strom) or gas (Gas). At runtime call route_with_sparte to prefer the commodity-specific entry over the unambiguous fallback registered via register.

§INSRPT shared PIDs (23001/23003/23004/23008)

These PIDs appear in both WiM Strom (5 WT) and WiM Gas (10 WT) AHBs:

// In WimModule (Strom):
router.register_with_sparte(23001, Sparte::Strom, "wim-insrpt");

// In WimGasModule (Gas):
router.register_with_sparte(23001, Sparte::Gas, "wim-gas-insrpt");
Source

pub fn route_with_sparte(&self, pid: u32, sparte: Sparte) -> Option<&str>

Look up the workflow name for pid, preferring the commodity-qualified entry for sparte over the unambiguous fallback.

Resolution order:

  1. commodity_table[(pid, sparte)] — registered via register_with_sparte
  2. table[pid] — registered via register (unambiguous fallback)

Returns None when neither table has an entry for pid.

§INSRPT routing example
use mako_engine::pid_router::PidRouter;
use mako_engine::types::Sparte;

let mut r = PidRouter::new();
r.register(23001, "wim-insrpt");                            // Strom fallback
r.register_with_sparte(23001, Sparte::Strom, "wim-insrpt");
r.register_with_sparte(23001, Sparte::Gas,   "wim-gas-insrpt");

assert_eq!(r.route_with_sparte(23001, Sparte::Strom), Some("wim-insrpt"));
assert_eq!(r.route_with_sparte(23001, Sparte::Gas),   Some("wim-gas-insrpt"));
assert_eq!(r.route(23001),                             Some("wim-insrpt"));
Source

pub fn route(&self, pid: u32) -> Option<&str>

Look up the workflow name for pid.

Returns None when pid has not been registered. The caller should dead-letter the message and return an appropriate error to the sender rather than panicking.

Source

pub fn registered_pids(&self) -> impl Iterator<Item = u32> + '_

Return an iterator over all registered PID values.

Useful for validation (e.g. comparing against PIDs declared in AHB profile JSON files to detect missing workflow implementations).

Source

pub fn len(&self) -> usize

Return the number of registered PID mappings.

Source

pub fn is_empty(&self) -> bool

Return true when no PIDs have been registered.

Trait Implementations§

Source§

impl Clone for PidRouter

Source§

fn clone(&self) -> PidRouter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PidRouter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PidRouter

Source§

fn default() -> PidRouter

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more