Skip to content

Commit

Permalink
fix: resolve further nits
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr committed Aug 22, 2024
1 parent 4db6097 commit 6f82e91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
14 changes: 1 addition & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl<T> Optional<T> for (T,) {
///
/// Handling multiple properties for `strip_option`
///
/// ```no_run
/// ```compile_fail
/// use typed_builder::TypedBuilder;
///
/// #[derive(TypedBuilder)]
Expand All @@ -402,16 +402,4 @@ impl<T> Optional<T> for (T,) {
/// value: Option<i32>,
/// }
/// ```
///
/// Handling empty properties for `strip_option`
///
/// ```no_run
/// use typed_builder::TypedBuilder;
///
/// #[derive(TypedBuilder)]
/// struct Foo {
/// #[builder(setter(strip_option()))]
/// value: Option<i32>,
/// }
/// ```
fn _compile_fail_tests() {}
10 changes: 9 additions & 1 deletion typed-builder-macro/src/field_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,12 @@ impl ApplyMeta for SetterSettings {
match expr {
AttrArg::Sub(sub) => {
let span = sub.span();
let mut strip_option = Strip::new(span);

if self.strip_option.is_none() {
let mut strip_option = Strip::new(span);
strip_option.apply_sub_attr(sub)?;
self.strip_option = Some(strip_option);

Ok(())
} else {
Err(Error::new(span, format!("Illegal setting - field is already {caption}")))
Expand Down Expand Up @@ -394,6 +395,13 @@ impl ApplyMeta for Strip {
fn apply_meta(&mut self, expr: AttrArg) -> Result<(), Error> {
match expr.name().to_string().as_str() {
"fallback" => {
if self.fallback.is_some() {
return Err(Error::new_spanned(
expr.name(),
format!("Duplicate fallback parameter {:?}", expr.name().to_string()),
));
}

let ident: syn::Ident = expr.key_value().map(|kv| kv.parse_value())??;
self.fallback = Some(ident);
Ok(())
Expand Down

0 comments on commit 6f82e91

Please sign in to comment.