Skip to content

Possible fix #47 Add flag Option for bool Flag#70

Open
GREX18 wants to merge 1 commit intofunnyboy-roks:mainfrom
GREX18:main
Open

Possible fix #47 Add flag Option for bool Flag#70
GREX18 wants to merge 1 commit intofunnyboy-roks:mainfrom
GREX18:main

Conversation

@GREX18
Copy link
Copy Markdown

@GREX18 GREX18 commented Apr 15, 2026

This should fix issue #47 by adding the flag option as well as some simple tests that could be expanded.
.unwrap doesn't work with it unfortunatley

Copy link
Copy Markdown
Owner

@funnyboy-roks funnyboy-roks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab at this! I don't think there were any changes made for the type-state builder, so that will need to be done. Apart from that, I have just a few comments!

Comment on lines +304 to +307
if self.attr.flag {
let attributes = &self.attr.attributes;
let konst = builder_attr.konst_kw();
return quote! { #(#attributes)* #[must_use = "You have created a flag type but not used it"] #builder_vis #konst fn #fn_ident(#self_param) -> #return_type { #[allow(deprecated)] { self.#inner.#field_i = Some(true); } self } }; }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not need to be duplicated from below. You should be able to just change the setter variable above and change the to_args_and_value function on FieldAttr to have no arguments.

}
// ensure it's a boolean attribute
if !matches!(&field.ty, Type::Path(tp) if tp.path.is_ident("bool")) {
bail!(ident.span() => "`flag` must affect a boolean attribute");
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps reword this to something like

Suggested change
bail!(ident.span() => "`flag` must affect a boolean attribute");
bail!(ident.span() => "`flag` may only be applied to a boolean field");

Comment thread bauer-macros/src/lib.rs
Comment on lines +228 to +231
} else if field.attr.flag {
quote! {
inner.#field_i.take().unwrap_or(false)
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the field on the builder hold a bool, rather than need to unwrap this option.

Comment thread bauer-macros/src/lib.rs
} else if let Some(default) = &field.attr.default {
let default = default.to_value(field.attr.into);
quote! {
// NOTE: not using Option::unwrap_or_else, since it's not stable in const
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this comment (and the one below)?

Comment thread bauer/tests/flag.rs
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the same macro pattern from the simple test in this one, so that all builder kinds are tested.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should not be included in here. The messages depend on what compiler you use and we're currently testing against stable.

@funnyboy-roks funnyboy-roks linked an issue Apr 18, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add flag Option for bool Flag

2 participants