updated macro

pull/2/head
ondra05 2023-08-19 23:57:48 +02:00
parent 55a0d5a15b
commit 2986f85f77
No known key found for this signature in database
GPG Key ID: 0DA6D2BB2285E881
2 changed files with 19 additions and 4 deletions

View File

@ -69,8 +69,8 @@ pub enum MemoryAccessReason {
}
impl_display!(for MemoryAccessReason => match {
Self::Load => "Load";
Self::Store => "Store";
Self::Load => const "Load";
Self::Store => const "Store";
});
impl From<LoadError> for crate::VmRunError {

View File

@ -17,13 +17,13 @@ macro_rules! impl_display {
};
(for $ty:ty => match {$(
$bind:pat => $fmt:literal $(,$($param:expr),* $(,)?)?;
$bind:pat => $($const:ident)? $fmt:literal $(,$($params:tt)*)?;
)*}) => {
impl ::core::fmt::Display for $ty {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self {
$(
$bind => write!(f, $fmt, $($($param),*)?)
$bind => $crate::utils::private::impl_display_match_fragment!($($const,)? f, $fmt $(, $($params)*)?)
),*
}
}
@ -31,6 +31,21 @@ macro_rules! impl_display {
}
}
#[doc(hidden)]
pub(crate) mod private {
macro_rules! impl_display_match_fragment {
(const, $f:expr, $lit:literal) => {
$f.write_str($lit)
};
($f:expr, $fmt:literal $(, $($params:tt)*)?) => {
write!($f, $fmt, $($($params)*)?)
};
}
pub(crate) use impl_display_match_fragment;
}
macro_rules! static_assert_eq(($l:expr, $r:expr $(,)?) => {
const _: [(); ($l != $r) as usize] = [];
});