forked from AbleOS/ableos
updated macro
This commit is contained in:
parent
26105bab70
commit
0d2949024c
|
@ -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 {
|
||||
|
|
|
@ -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] = [];
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue