diff --git a/Cargo.toml b/Cargo.toml index 51c22f0..3b9097b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,8 @@ +[workspace] +members = [ + "derive" +] + [package] name = "bincode" version = "2.0.0-dev" # remember to update html_root_url and bincode_derive diff --git a/derive/src/derive_enum.rs b/derive/src/derive_enum.rs index cb1d563..9e14519 100644 --- a/derive/src/derive_enum.rs +++ b/derive/src/derive_enum.rs @@ -3,7 +3,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; use quote::quote; use quote::ToTokens; -use syn::{spanned::Spanned, Field, Fields, Generics, Ident, Index, Variant}; +use syn::{spanned::Spanned, Fields, Generics, Ident, Index, Variant}; pub struct DeriveEnum { name: Ident, generics: Generics, @@ -21,7 +21,7 @@ impl DeriveEnum { }) } - pub fn to_encodable(self) -> Result { + pub fn generate_encodable(self) -> Result { let DeriveEnum { name, generics, @@ -56,7 +56,7 @@ impl DeriveEnum { Ok(result.into()) } - pub fn to_decodable(self) -> Result { + pub fn generate_decodable(self) -> Result { let DeriveEnum { name, generics, @@ -145,7 +145,7 @@ fn fields_to_names(fields: &Fields) -> Vec { fn field_names_to_encodable(names: &[TokenStream2]) -> Vec { names - .into_iter() + .iter() .map(|field| { quote! { bincode::enc::Encodeable::encode(#field, &mut encoder)?; @@ -165,7 +165,7 @@ fn fields_to_constructable_names(fields: &Fields) -> Vec { .unnamed .iter() .enumerate() - .map(|(i, f)| Index::from(i).to_token_stream()) + .map(|(i, _)| Index::from(i).to_token_stream()) .collect(), syn::Fields::Unit => Vec::new(), } @@ -173,7 +173,7 @@ fn fields_to_constructable_names(fields: &Fields) -> Vec { fn field_names_to_decodable(names: &[TokenStream2]) -> Vec { names - .into_iter() + .iter() .map(|field| { quote! { #field: bincode::de::Decodable::decode(&mut decoder)?, diff --git a/derive/src/derive_struct.rs b/derive/src/derive_struct.rs index c955dd1..ff63e74 100644 --- a/derive/src/derive_struct.rs +++ b/derive/src/derive_struct.rs @@ -1,8 +1,8 @@ use crate::Result; use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; -use quote::{quote, quote_spanned, ToTokens}; -use syn::{spanned::Spanned, Generics, Ident, Index}; +use quote::{quote, ToTokens}; +use syn::{Generics, Ident, Index}; pub struct DeriveStruct { name: Ident, @@ -33,7 +33,7 @@ impl DeriveStruct { }) } - pub fn to_encodable(self) -> Result { + pub fn generate_encodable(self) -> Result { let DeriveStruct { name, generics, @@ -63,7 +63,7 @@ impl DeriveStruct { Ok(result.into()) } - pub fn to_decodable(self) -> Result { + pub fn generate_decodable(self) -> Result { let DeriveStruct { name, generics, diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 2925525..2e91110 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -22,11 +22,11 @@ fn derive_encodable_inner(input: DeriveInput) -> Result { match input.data { syn::Data::Struct(struct_definition) => { DeriveStruct::parse(input.ident, input.generics, struct_definition) - .and_then(|str| str.to_encodable()) + .and_then(|str| str.generate_encodable()) } syn::Data::Enum(enum_definition) => { DeriveEnum::parse(input.ident, input.generics, enum_definition) - .and_then(|str| str.to_encodable()) + .and_then(|str| str.generate_encodable()) } syn::Data::Union(_) => Err(Error::UnionNotSupported), } @@ -42,11 +42,11 @@ fn derive_decodable_inner(input: DeriveInput) -> Result { match input.data { syn::Data::Struct(struct_definition) => { DeriveStruct::parse(input.ident, input.generics, struct_definition) - .and_then(|str| str.to_decodable()) + .and_then(|str| str.generate_decodable()) } syn::Data::Enum(enum_definition) => { DeriveEnum::parse(input.ident, input.generics, enum_definition) - .and_then(|str| str.to_decodable()) + .and_then(|str| str.generate_decodable()) } syn::Data::Union(_) => Err(Error::UnionNotSupported), }