Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 committed Sep 5, 2023
1 parent 2343382 commit 4d745ac
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 152 deletions.
26 changes: 26 additions & 0 deletions code/xcvm/lib/core/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,29 @@ impl core::fmt::Display for DecodeError {
}
}
}

/// Defines conversions between protocol buffer message `$pb` and Rust type
/// `$ty`.
///
/// Specifically, implements `TryFrom<$pb> for $ty` and `From<$ty> for $pb`.
/// That is, conversion from protocol message is fallible while conversion to
/// protocol message isn’t. The error for the `TryFrom` conversion is `()`.
macro_rules! define_conversion {
(($pb_name:ident: $pb:ty) -> { $($from_pb:tt)* }
($ty_name:ident: $ty:ty) -> { $($from_ty:tt)* }) => {
impl TryFrom<$pb> for $ty {
type Error = ();
fn try_from($pb_name: $pb) -> Result<Self, Self::Error> {
$($from_pb)*
}
}

impl From<$ty> for $pb {
fn from($ty_name: $ty) -> $pb {
$($from_ty)*
}
}
}
}

use define_conversion;
Loading

0 comments on commit 4d745ac

Please sign in to comment.