pub trait ProtocolMessage: Sized {
// Required method
fn round(&self) -> u16;
}Expand description
Message of MPC protocol
MPC protocols typically consist of several rounds, each round has differently typed message.
ProtocolMessage and RoundMessage traits are used to examine received message: ProtocolMessage::round
determines which round message belongs to, and then RoundMessage trait can be used to retrieve
actual round-specific message.
You should derive these traits using proc macro (requires derive feature):
use round_based::ProtocolMessage;
#[derive(ProtocolMessage)]
pub enum Message {
Round1(Msg1),
Round2(Msg2),
// ...
}
pub struct Msg1 { /* ... */ }
pub struct Msg2 { /* ... */ }This desugars into:
use round_based::rounds_router::{ProtocolMessage, RoundMessage};
pub enum Message {
Round1(Msg1),
Round2(Msg2),
// ...
}
pub struct Msg1 { /* ... */ }
pub struct Msg2 { /* ... */ }
impl ProtocolMessage for Message {
fn round(&self) -> u16 {
match self {
Message::Round1(_) => 1,
Message::Round2(_) => 2,
// ...
}
}
}
impl RoundMessage<Msg1> for Message {
const ROUND: u16 = 1;
fn to_protocol_message(round_message: Msg1) -> Self {
Message::Round1(round_message)
}
fn from_protocol_message(protocol_message: Self) -> Result<Msg1, Self> {
match protocol_message {
Message::Round1(msg) => Ok(msg),
msg => Err(msg),
}
}
}
impl RoundMessage<Msg2> for Message {
const ROUND: u16 = 2;
fn to_protocol_message(round_message: Msg2) -> Self {
Message::Round2(round_message)
}
fn from_protocol_message(protocol_message: Self) -> Result<Msg2, Self> {
match protocol_message {
Message::Round2(msg) => Ok(msg),
msg => Err(msg),
}
}
}Required Methods§
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.