pub trait PlainMessageProcessor:
Send
+ Sync
+ Clone {
// Required methods
fn process_incoming<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<Option<PlainMessage>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn process_outgoing<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<Option<PlainMessage>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
Expand description
Trait for processing DIDComm messages in TAP nodes
The PlainMessageProcessor
trait defines the interface for message processors
that handle DIDComm messages flowing through the TAP node. Processors act
as middleware, allowing for validation, transformation, logging, metrics
collection, and other operations on messages.
§Design Patterns
This trait follows the Chain of Responsibility pattern, where each processor can either:
- Pass the message along unchanged
- Transform the message before passing it along
- Filter out (drop) the message by returning None
- Perform side effects during processing (logging, metrics, etc.)
§Thread Safety
All implementations must be Send + Sync + Clone
to ensure they can be
safely used in multithreaded environments and composed into processor chains.
§Implementation Guidelines
When implementing a custom processor:
- Ensure both
process_incoming
andprocess_outgoing
are implemented - Be mindful of performance in high-throughput environments
- Consider making processors stateless when possible
- Use the processor’s Clone trait to avoid expensive setup/teardown
- Document any side effects or transformations clearly
§Examples
#[derive(Clone, Debug)]
struct MyCustomProcessor;
#[async_trait]
impl PlainMessageProcessor for MyCustomProcessor {
async fn process_incoming(&self, message: PlainMessage) -> Result<Option<PlainMessage>> {
// Process incoming message - e.g., validate fields, log, transform
println!("Processing incoming message: {}", message.id);
Ok(Some(message)) // Pass message along unchanged
}
async fn process_outgoing(&self, message: PlainMessage) -> Result<Option<PlainMessage>> {
// Process outgoing message
println!("Processing outgoing message: {}", message.id);
Ok(Some(message)) // Pass message along unchanged
}
}
Required Methods§
Sourcefn process_incoming<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<Option<PlainMessage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn process_incoming<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<Option<PlainMessage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Process an incoming message received by the node
This method handles messages that are being received by the TAP node from external sources. Implementations can validate, transform, or filter these messages before they are routed to their target agents.
§Parameters
message
- The DIDComm message to process
§Returns
Ok(Some(message))
- The message to pass to the next processorOk(None)
- Drop the message (do not process further)Err(e)
- Processing error
Sourcefn process_outgoing<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<Option<PlainMessage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn process_outgoing<'life0, 'async_trait>(
&'life0 self,
message: PlainMessage,
) -> Pin<Box<dyn Future<Output = Result<Option<PlainMessage>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Process an outgoing message being sent from the node
This method handles messages that are being sent from the TAP node to external recipients. Implementations can transform these messages for compatibility, add headers, perform logging, or filter messages before they are delivered.
§Parameters
message
- The DIDComm message to process
§Returns
Ok(Some(message))
- The message to pass to the next processorOk(None)
- Drop the message (do not process further)Err(e)
- Processing error
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.