Skip to content

Commit

Permalink
Allow unquoted block expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
TedDriggs committed Feb 7, 2024
1 parent d6cc48b commit 19ac1ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions derive_builder/tests/builder_field_custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::num::ParseIntError;

#[derive(Debug, PartialEq, Default, Builder, Clone)]
pub struct Lorem {
#[builder(field(ty = "Option<usize>", build = "self.ipsum.unwrap_or(42) + 1"))]
#[builder(field(ty = "Option<usize>", build = self.ipsum.unwrap_or(42) + 1))]
ipsum: usize,

#[builder(setter(into), field(ty = "String", build = "self.dolor.parse()?"))]
#[builder(setter(into), field(ty = "String", build = self.dolor.parse()?))]
dolor: u32,
}

Expand Down
8 changes: 8 additions & 0 deletions derive_builder_core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ impl darling::FromMeta for BlockContents {
Err(darling::Error::unexpected_lit_type(value))
}
}

fn from_expr(expr: &syn::Expr) -> darling::Result<Self> {
if let syn::Expr::Lit(lit) = expr {
Self::from_value(&lit.lit)
} else {
Ok(Self::from(expr.clone()))
}
}
}

#[cfg(test)]
Expand Down

0 comments on commit 19ac1ea

Please sign in to comment.