From fd9af817fdb2edc4810b53e3935d8af0b45c4d82 Mon Sep 17 00:00:00 2001 From: Artem Vorotnikov Date: Mon, 17 Apr 2023 06:49:51 +0400 Subject: [PATCH] Remove Rlp prefix from proc macro names --- derive/src/de.rs | 6 +++--- derive/src/en.rs | 8 ++++---- derive/src/lib.rs | 12 ++++++------ src/lib.rs | 4 +--- tests/rlp.rs | 8 ++++---- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/derive/src/de.rs b/derive/src/de.rs index 07bf7e2..3cdc546 100644 --- a/derive/src/de.rs +++ b/derive/src/de.rs @@ -6,7 +6,7 @@ pub fn impl_decodable(ast: &syn::DeriveInput) -> TokenStream { let body = if let syn::Data::Struct(s) = &ast.data { s } else { - panic!("#[derive(RlpDecodable)] is only defined for structs."); + panic!("#[derive(Decodable)] is only defined for structs."); }; let stmts: Vec<_> = body @@ -60,13 +60,13 @@ pub fn impl_decodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { let body = if let syn::Data::Struct(s) = &ast.data { s } else { - panic!("#[derive(RlpEncodableWrapper)] is only defined for structs."); + panic!("#[derive(EncodableWrapper)] is only defined for structs."); }; assert_eq!( body.fields.iter().count(), 1, - "#[derive(RlpEncodableWrapper)] is only defined for structs with one field." + "#[derive(EncodableWrapper)] is only defined for structs with one field." ); let name = &ast.ident; diff --git a/derive/src/en.rs b/derive/src/en.rs index 13c5196..3b32d93 100644 --- a/derive/src/en.rs +++ b/derive/src/en.rs @@ -6,7 +6,7 @@ pub fn impl_encodable(ast: &syn::DeriveInput) -> TokenStream { let body = if let syn::Data::Struct(s) = &ast.data { s } else { - panic!("#[derive(RlpEncodable)] is only defined for structs."); + panic!("#[derive(Encodable)] is only defined for structs."); }; let length_stmts: Vec<_> = body @@ -62,7 +62,7 @@ pub fn impl_encodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { let body = if let syn::Data::Struct(s) = &ast.data { s } else { - panic!("#[derive(RlpEncodableWrapper)] is only defined for structs."); + panic!("#[derive(EncodableWrapper)] is only defined for structs."); }; let ident = { @@ -71,7 +71,7 @@ pub fn impl_encodable_wrapper(ast: &syn::DeriveInput) -> TokenStream { let field = fields.first().expect("fields.len() == 1; qed"); field_ident(0, field) } else { - panic!("#[derive(RlpEncodableWrapper)] is only defined for structs with one field.") + panic!("#[derive(EncodableWrapper)] is only defined for structs with one field.") } }; @@ -101,7 +101,7 @@ pub fn impl_max_encoded_len(ast: &syn::DeriveInput) -> TokenStream { let body = if let syn::Data::Struct(s) = &ast.data { s } else { - panic!("#[derive(RlpEncodable)] is only defined for structs."); + panic!("#[derive(Encodable)] is only defined for structs."); }; let stmts: Vec<_> = body diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 27b45c2..c61941e 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -1,4 +1,4 @@ -//! Derive macro for `#[derive(RlpEncodable, RlpDecodable)]`. +//! Derive macro for `#[derive(Encodable, Decodable)]`. //! //! For example of usage see `./tests/rlp.rs`. //! @@ -20,35 +20,35 @@ use de::*; use en::*; use proc_macro::TokenStream; -#[proc_macro_derive(RlpEncodable, attributes(rlp))] +#[proc_macro_derive(Encodable, attributes(rlp))] pub fn encodable(input: TokenStream) -> TokenStream { let ast = syn::parse(input).unwrap(); let gen = impl_encodable(&ast); gen.into() } -#[proc_macro_derive(RlpEncodableWrapper, attributes(rlp))] +#[proc_macro_derive(EncodableWrapper, attributes(rlp))] pub fn encodable_wrapper(input: TokenStream) -> TokenStream { let ast = syn::parse(input).unwrap(); let gen = impl_encodable_wrapper(&ast); gen.into() } -#[proc_macro_derive(RlpMaxEncodedLen, attributes(rlp))] +#[proc_macro_derive(MaxEncodedLen, attributes(rlp))] pub fn max_encoded_len(input: TokenStream) -> TokenStream { let ast = syn::parse(input).unwrap(); let gen = impl_max_encoded_len(&ast); gen.into() } -#[proc_macro_derive(RlpDecodable, attributes(rlp))] +#[proc_macro_derive(Decodable, attributes(rlp))] pub fn decodable(input: TokenStream) -> TokenStream { let ast = syn::parse(input).unwrap(); let gen = impl_decodable(&ast); gen.into() } -#[proc_macro_derive(RlpDecodableWrapper, attributes(rlp))] +#[proc_macro_derive(DecodableWrapper, attributes(rlp))] pub fn decodable_wrapper(input: TokenStream) -> TokenStream { let ast = syn::parse(input).unwrap(); let gen = impl_decodable_wrapper(&ast); diff --git a/src/lib.rs b/src/lib.rs index 92e4b2c..087d7b5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,4 @@ pub use encode::{ pub use types::*; #[cfg(feature = "derive")] -pub use fastrlp_derive::{ - RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper, RlpMaxEncodedLen, -}; +pub use fastrlp_derive::{Decodable, DecodableWrapper, Encodable, EncodableWrapper, MaxEncodedLen}; diff --git a/tests/rlp.rs b/tests/rlp.rs index 18b5c16..de9ca77 100644 --- a/tests/rlp.rs +++ b/tests/rlp.rs @@ -4,12 +4,12 @@ use ethnum::U256; use fastrlp::*; use hex_literal::hex; -#[derive(Debug, PartialEq, RlpEncodable, RlpDecodable)] +#[derive(Debug, PartialEq, Encodable, Decodable)] struct Item { a: Bytes, } -#[derive(Debug, PartialEq, RlpEncodable, RlpDecodable, RlpMaxEncodedLen)] +#[derive(Debug, PartialEq, Encodable, Decodable, MaxEncodedLen)] struct Test4Numbers { a: u8, b: u64, @@ -17,10 +17,10 @@ struct Test4Numbers { d: U256, } -#[derive(Debug, PartialEq, RlpEncodableWrapper, RlpDecodableWrapper)] +#[derive(Debug, PartialEq, EncodableWrapper, DecodableWrapper)] pub struct W(Test4Numbers); -#[derive(Debug, PartialEq, RlpEncodable)] +#[derive(Debug, PartialEq, Encodable)] struct Test4NumbersGenerics<'a, D: Encodable> { a: u8, b: u64,