diff --git a/rmp/Cargo.toml b/rmp/Cargo.toml index a55f843..80ac58a 100644 --- a/rmp/Cargo.toml +++ b/rmp/Cargo.toml @@ -14,8 +14,6 @@ edition = "2021" [dependencies] byteorder = { version = "1.4.2", default-features = false } num-traits = { version = "0.2.14", default-features = false } -# This is macro_only ;) -paste = "1.0" [features] default = ["std"] diff --git a/rmp/src/decode/mod.rs b/rmp/src/decode/mod.rs index 8b5d813..439ae8e 100644 --- a/rmp/src/decode/mod.rs +++ b/rmp/src/decode/mod.rs @@ -54,7 +54,7 @@ impl RmpReadErr for std::io::Error {} impl RmpReadErr for core::convert::Infallible {} macro_rules! read_byteorder_utils { - ($($name:ident => $tp:ident),* $(,)?) => { + ($($name:ident => $tp:ty => $func:ident),* $(,)?) => { $( #[inline] #[doc(hidden)] @@ -62,9 +62,7 @@ macro_rules! read_byteorder_utils { const SIZE: usize = core::mem::size_of::<$tp>(); let mut buf: [u8; SIZE] = [0u8; SIZE]; self.read_exact_buf(&mut buf).map_err(ValueReadError::InvalidDataRead)?; - Ok(paste::paste! { - ::[](&mut buf) - }) + Ok(::$func(&mut buf)) } )* }; @@ -119,14 +117,14 @@ pub trait RmpRead: sealed::Sealed { } read_byteorder_utils!( - read_data_u16 => u16, - read_data_u32 => u32, - read_data_u64 => u64, - read_data_i16 => i16, - read_data_i32 => i32, - read_data_i64 => i64, - read_data_f32 => f32, - read_data_f64 => f64 + read_data_u16 => u16 => read_u16, + read_data_u32 => u32 => read_u32, + read_data_u64 => u64 => read_u64, + read_data_i16 => i16 => read_i16, + read_data_i32 => i32 => read_i32, + read_data_i64 => i64 => read_i64, + read_data_f32 => f32 => read_f32, + read_data_f64 => f64 => read_f64, ); } @@ -134,7 +132,7 @@ pub trait RmpRead: sealed::Sealed { * HACK: rmpv & rmp-erde used the internal read_data_* functions. * * Since adding no_std support moved these functions to the RmpRead trait, - * this broke compatiblity (despite changing no public APIs). + * this broke compatibility (despite changing no public APIs). * * In theory, we could update rmpv and rmp-serde to use the new APIS, * but that would be needless churn (and might surprise users who just want to update rmp proper). @@ -147,21 +145,21 @@ pub trait RmpRead: sealed::Sealed { */ macro_rules! wrap_data_funcs_for_compatibility { - ($($tp:ident),* $(,)?) => { - $(paste::paste! { + ($($tp:ty => $func:ident),* $(,)?) => { + $( #[cfg(feature = "std")] #[doc(hidden)] #[deprecated(note = "internal function. rmpv & rmp-serde need to switch to RmpRead")] - pub fn [] (buf: &mut R) -> Result<$tp, ValueReadError> { - buf.[]() + pub fn $func(buf: &mut R) -> Result<$tp, ValueReadError> { + buf.$func() } - })* + )* }; } wrap_data_funcs_for_compatibility!( - u8, u16, u32, u64, - i8, i16, i32, i64, - f32, f64 + u8 => read_data_u8, u16 => read_data_u16, u32 => read_data_u32, u64 => read_data_u64, + i8 => read_data_i8, i16 => read_data_i16, i32 => read_data_i32, i64 => read_data_i64, + f32 => read_data_f32, f64 => read_data_f64, ); #[cfg(feature = "std")] @@ -174,16 +172,6 @@ impl RmpRead for T { } } -// An error returned from the `write_marker` and `write_fixval` functions. -struct MarkerWriteError(E); - -impl From for MarkerWriteError { - #[cold] - fn from(err: E) -> Self { - Self(err) - } -} - /// An error that can occur when attempting to read a MessagePack marker from the reader. #[derive(Debug)] #[allow(deprecated)] // Needed for backwards compat diff --git a/rmp/src/encode/mod.rs b/rmp/src/encode/mod.rs index 9627339..eda43f9 100644 --- a/rmp/src/encode/mod.rs +++ b/rmp/src/encode/mod.rs @@ -114,16 +114,14 @@ mod sealed { } macro_rules! write_byteorder_utils { - ($($name:ident => $tp:ident),* $(,)?) => { + ($($name:ident => $tp:ty => $func:ident),* $(,)?) => { $( #[inline] #[doc(hidden)] fn $name(&mut self, val: $tp) -> Result<(), DataWriteError> where Self: Sized { const SIZE: usize = core::mem::size_of::<$tp>(); let mut buf: [u8; SIZE] = [0u8; SIZE]; - paste::paste! { - ::[](&mut buf, val); - } + ::$func(&mut buf, val); self.write_bytes(&buf).map_err(DataWriteError) } )* @@ -170,14 +168,14 @@ pub trait RmpWrite: sealed::Sealed { } write_byteorder_utils!( - write_data_u16 => u16, - write_data_u32 => u32, - write_data_u64 => u64, - write_data_i16 => i16, - write_data_i32 => i32, - write_data_i64 => i64, - write_data_f32 => f32, - write_data_f64 => f64 + write_data_u16 => u16 => write_u16, + write_data_u32 => u32 => write_u32, + write_data_u64 => u64 => write_u64, + write_data_i16 => i16 => write_i16, + write_data_i32 => i32 => write_i32, + write_data_i64 => i64 => write_i64, + write_data_f32 => f32 => write_f32, + write_data_f64 => f64 => write_f64, ); }