updated macro

This commit is contained in:
Erin 2023-08-19 23:57:48 +02:00 committed by ondra05
parent f468a02ad4
commit cb35c86add
2 changed files with 19 additions and 4 deletions

View file

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

View file

@ -17,13 +17,13 @@ macro_rules! impl_display {
}; };
(for $ty:ty => match {$( (for $ty:ty => match {$(
$bind:pat => $fmt:literal $(,$($param:expr),* $(,)?)?; $bind:pat => $($const:ident)? $fmt:literal $(,$($params:tt)*)?;
)*}) => { )*}) => {
impl ::core::fmt::Display for $ty { impl ::core::fmt::Display for $ty {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
match self { 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 $(,)?) => { macro_rules! static_assert_eq(($l:expr, $r:expr $(,)?) => {
const _: [(); ($l != $r) as usize] = []; const _: [(); ($l != $r) as usize] = [];
}); });