Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Oct 28, 2024
1 parent b6dc13e commit ac06f6b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions manul/src/protocol/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ use private::{MessagePayload, ProtocolMessageWrapper};

/// A serialized part of the protocol message.
///
/// These would usually be generated separately by the round, but delivered together to [`Round::receive_message`].
/// These would usually be generated separately by the round, but delivered together to
/// [`Round::receive_message`](`crate::protocol::Round::receive_message`).
pub trait ProtocolMessage: ProtocolMessageWrapper {
/// The error specific to deserializing this message.
///
/// Used to distinguish which deserialization failed in [`Round::receive_message`]
/// Used to distinguish which deserialization failed in
/// [`Round::receive_message`](`crate::protocol::Round::receive_message`)
/// and store the corresponding message in the evidence.
type Error: From<String>;

Expand All @@ -40,7 +42,7 @@ pub trait ProtocolMessage: ProtocolMessageWrapper {
Self::new_inner(None)
}

/// Creates a new serialized direct message.
/// Creates a new serialized message.
fn new<P: Protocol, T: Serialize>(message: T) -> Result<Self, LocalError> {
let payload = MessagePayload(P::serialize(message)?);
Ok(Self::new_inner(Some(payload)))
Expand All @@ -64,7 +66,8 @@ pub trait ProtocolMessage: ProtocolMessageWrapper {

/// Returns `Ok(())` if the message cannot be deserialized into `T`.
///
/// This is intended to be used in the implementations of [`Protocol::verify_direct_message_is_invalid`].
/// This is intended to be used in the implementations of
/// [`Protocol::verify_direct_message_is_invalid`] or [`Protocol::verify_echo_broadcast_is_invalid`].
fn verify_is_not<P: Protocol, T: for<'de> Deserialize<'de>>(&self) -> Result<(), MessageValidationError> {
if self.deserialize::<P, T>().is_err() {
Ok(())
Expand All @@ -77,7 +80,8 @@ pub trait ProtocolMessage: ProtocolMessageWrapper {

/// Returns `Ok(())` if the message contains a payload.
///
/// This is intended to be used in the implementations of [`Protocol::verify_direct_message_is_invalid`].
/// This is intended to be used in the implementations of
/// [`Protocol::verify_direct_message_is_invalid`] or [`Protocol::verify_echo_broadcast_is_invalid`].
fn verify_is_some(&self) -> Result<(), MessageValidationError> {
if self.maybe_message().is_some() {
Ok(())
Expand All @@ -88,7 +92,7 @@ pub trait ProtocolMessage: ProtocolMessageWrapper {
}
}

/// Deserializes the direct message.
/// Deserializes the message into `T`.
fn deserialize<P: Protocol, T: for<'de> Deserialize<'de>>(&self) -> Result<T, Self::Error> {
let payload = self
.maybe_message()
Expand Down

0 comments on commit ac06f6b

Please sign in to comment.