Skip to content

Commit

Permalink
fix hundreds of clippy warnings
Browse files Browse the repository at this point in the history
- aLlow single instances of: `clippy::wrong_self_convention`, `clippy::enum_variant_names` and `clippy::vec_box`.
- rustfmt.
  • Loading branch information
joseluis authored and knickish committed Nov 18, 2024
1 parent d2bfd0b commit d42a6b2
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 249 deletions.
60 changes: 24 additions & 36 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,118 +30,106 @@ mod parse;
pub fn derive_ser_bin(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse::parse_data(input);

if let Some(proxy) = shared::attrs_proxy(&input.attributes()) {
return derive_ser_bin_proxy(&proxy, &input.name());
if let Some(proxy) = shared::attrs_proxy(input.attributes()) {
return derive_ser_bin_proxy(&proxy, input.name());
}

// ok we have an ident, its either a struct or a enum
let ts = match &input {
match &input {
parse::Data::Struct(struct_) if struct_.named => derive_ser_bin_struct(struct_),
parse::Data::Struct(struct_) => derive_ser_bin_struct_unnamed(struct_),
parse::Data::Enum(enum_) => derive_ser_bin_enum(enum_),
_ => unimplemented!("Only structs and enums are supported"),
};

ts
}
}

#[cfg(feature = "binary")]
#[proc_macro_derive(DeBin, attributes(nserde))]
pub fn derive_de_bin(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse::parse_data(input);

if let Some(proxy) = shared::attrs_proxy(&input.attributes()) {
return derive_de_bin_proxy(&proxy, &input.name());
if let Some(proxy) = shared::attrs_proxy(input.attributes()) {
return derive_de_bin_proxy(&proxy, input.name());
}

// ok we have an ident, its either a struct or a enum
let ts = match &input {
match &input {
parse::Data::Struct(struct_) if struct_.named => derive_de_bin_struct(struct_),
parse::Data::Struct(struct_) => derive_de_bin_struct_unnamed(struct_),
parse::Data::Enum(enum_) => derive_de_bin_enum(enum_),

_ => unimplemented!("Only structs and enums are supported"),
};

ts
}
}

#[cfg(feature = "ron")]
#[proc_macro_derive(SerRon, attributes(nserde))]
pub fn derive_ser_ron(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse::parse_data(input);

if let Some(proxy) = shared::attrs_proxy(&input.attributes()) {
return derive_ser_ron_proxy(&proxy, &input.name());
if let Some(proxy) = shared::attrs_proxy(input.attributes()) {
return derive_ser_ron_proxy(&proxy, input.name());
}

// ok we have an ident, its either a struct or a enum
let ts = match &input {
match &input {
parse::Data::Struct(struct_) if struct_.named => derive_ser_ron_struct(struct_),
parse::Data::Struct(struct_) => derive_ser_ron_struct_unnamed(struct_),
parse::Data::Enum(enum_) => derive_ser_ron_enum(enum_),
_ => unimplemented!("Only structs and enums are supported"),
};

ts
}
}

#[cfg(feature = "ron")]
#[proc_macro_derive(DeRon, attributes(nserde))]
pub fn derive_de_ron(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse::parse_data(input);

if let Some(proxy) = shared::attrs_proxy(&input.attributes()) {
return derive_de_ron_proxy(&proxy, &input.name());
if let Some(proxy) = shared::attrs_proxy(input.attributes()) {
return derive_de_ron_proxy(&proxy, input.name());
}

// ok we have an ident, its either a struct or a enum
let ts = match &input {
match &input {
parse::Data::Struct(struct_) if struct_.named => derive_de_ron_struct(struct_),
parse::Data::Struct(struct_) => derive_de_ron_struct_unnamed(struct_),
parse::Data::Enum(enum_) => derive_de_ron_enum(enum_),
_ => unimplemented!("Only structs and enums are supported"),
};

ts
}
}

#[cfg(feature = "json")]
#[proc_macro_derive(SerJson, attributes(nserde))]
pub fn derive_ser_json(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse::parse_data(input);

if let Some(proxy) = shared::attrs_proxy(&input.attributes()) {
return derive_ser_json_proxy(&proxy, &input.name());
if let Some(proxy) = shared::attrs_proxy(input.attributes()) {
return derive_ser_json_proxy(&proxy, input.name());
}

// ok we have an ident, its either a struct or a enum
let ts = match &input {
match &input {
parse::Data::Struct(struct_) if struct_.named => derive_ser_json_struct(struct_),
parse::Data::Struct(struct_) => derive_ser_json_struct_unnamed(struct_),
parse::Data::Enum(enum_) => derive_ser_json_enum(enum_),
_ => unimplemented!(""),
};

ts
}
}

#[cfg(feature = "json")]
#[proc_macro_derive(DeJson, attributes(nserde))]
pub fn derive_de_json(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse::parse_data(input);

if let Some(proxy) = shared::attrs_proxy(&input.attributes()) {
return derive_de_json_proxy(&proxy, &input.name());
if let Some(proxy) = shared::attrs_proxy(input.attributes()) {
return derive_de_json_proxy(&proxy, input.name());
}

// ok we have an ident, its either a struct or a enum
let ts = match &input {
match &input {
parse::Data::Struct(struct_) if struct_.named => derive_de_json_struct(struct_),
parse::Data::Struct(struct_) => derive_de_json_struct_unnamed(struct_),
parse::Data::Enum(enum_) => derive_de_json_enum(enum_),
parse::Data::Union(_) => unimplemented!("Unions are not supported"),
};

ts
}
}
Loading

0 comments on commit d42a6b2

Please sign in to comment.