macro_rules! impl_tap_message {
($type:ty) => { ... };
($type:ty, optional_transaction_id) => { ... };
($type:ty, thread_based) => { ... };
($type:ty, generated_id) => { ... };
}Expand description
Macro to implement TapMessage for a struct.
This macro implements the TapMessage trait for a struct that implements TapMessageBody. It supports different message field structures with specialized variants.
§Variants
§Basic (Standard transaction_id field)
Use this variant for message types with a required transaction_id: String field:
ⓘ
// Example usage - this won't be run as a test
use tap_msg::impl_tap_message;
impl_tap_message!(Transfer);§Optional Transaction ID
Use this variant for message types with an optional transaction_id: Option<String> field:
ⓘ
// Example usage - this won't be run as a test
use tap_msg::impl_tap_message;
impl_tap_message!(Presentation, optional_transaction_id);§Thread-based Messages
Use this variant for message types with a thid: Option<String> field but no transaction_id:
ⓘ
// Example usage - this won't be run as a test
use tap_msg::impl_tap_message;
impl_tap_message!(DIDCommPresentation, thread_based);§Generated ID
Use this variant for message types with neither transaction_id nor thread_id fields:
ⓘ
// Example usage - this won't be run as a test
use tap_msg::impl_tap_message;
impl_tap_message!(ErrorBody, generated_id);§Complete Example
ⓘ
// Example usage - this won't be run as a test
use tap_msg::impl_tap_message;
use tap_msg::message::tap_message_trait::{TapMessageBody, TapMessage};
use tap_msg::error::Result;
use serde::{Serialize, Deserialize};
use crate::didcomm::PlainMessage;
// Your struct that implements TapMessageBody
#[derive(Serialize, Deserialize)]
struct MyMessage {
transaction_id: String,
// other fields...
}
impl TapMessageBody for MyMessage {
fn validate(&self) -> Result<()> {
Ok(())
}
// Note: This is a static method, not an instance method
fn message_type() -> &'static str {
"my-message"
}
fn to_didcomm(&self, from_did: &str) -> Result<PlainMessage> {
// Implementation omitted
unimplemented!()
}
}
// Implement TapMessage trait
impl_tap_message!(MyMessage);