Skip to content

Commit

Permalink
remove warnings for structs that have only one field
Browse files Browse the repository at this point in the history
  • Loading branch information
maccesch committed Jun 10, 2023
1 parent 851bb53 commit 2d58bc0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "default-struct-builder"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["Marc-Stefan Cassola"]
description = "Generates builder methods of every field of a struct."
Expand Down
12 changes: 9 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) struct DefaultBuilderDeriveInput {
#[darling(attributes(builder), forward_attrs(allow, doc, cfg))]
pub(crate) struct StructField {
pub(crate) ident: Option<syn::Ident>,
pub(crate) ty: syn::Type,
pub(crate) ty: Type,
pub(crate) attrs: Vec<syn::Attribute>,

#[darling(default)]
Expand Down Expand Up @@ -48,6 +48,12 @@ impl ToTokens for DefaultBuilderDeriveInput {

let mut methods = vec![];

let dot_dot_self = if fields.len() == 1 {
quote! {}
} else {
quote! { ..self }
};

for f in fields.clone().into_iter() {
let name = f.ident.as_ref().expect("named field");

Expand Down Expand Up @@ -196,7 +202,7 @@ impl ToTokens for DefaultBuilderDeriveInput {
{
Self {
#name: value.into(),
..self
#dot_dot_self
}
}
})
Expand All @@ -206,7 +212,7 @@ impl ToTokens for DefaultBuilderDeriveInput {
pub fn #name(self, value: #ty) -> Self {
Self {
#name: value,
..self
#dot_dot_self
}
}
});
Expand Down

0 comments on commit 2d58bc0

Please sign in to comment.