Skip to content

Commit

Permalink
Remove Rlp prefix from proc macro names
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 committed Apr 17, 2023
1 parent 808714f commit fd9af81
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
6 changes: 3 additions & 3 deletions derive/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions derive/src/en.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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.")
}
};

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Derive macro for `#[derive(RlpEncodable, RlpDecodable)]`.
//! Derive macro for `#[derive(Encodable, Decodable)]`.
//!
//! For example of usage see `./tests/rlp.rs`.
//!
Expand All @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
8 changes: 4 additions & 4 deletions tests/rlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ 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,
c: U256,
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,
Expand Down

0 comments on commit fd9af81

Please sign in to comment.