Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve darling::util::Flag #174

Closed
TedDriggs opened this issue Apr 6, 2022 · 0 comments · Fixed by #179
Closed

Improve darling::util::Flag #174

TedDriggs opened this issue Apr 6, 2022 · 0 comments · Fixed by #179

Comments

@TedDriggs
Copy link
Owner

Right now, Flag has some issues that limit its usefulness:

  1. It has no span information, so it's impossible to create good errors on a Flag
  2. It hides its optionality, which means Option handling is verbose #161 would need special logic to infer that a Flag can be implicitly defaulted.

Proposed API

Deprecate darling::util::Flag in favor of... Word?

pub struct Word(Span);

impl Spanned for Word {}

This would then be used in conjunction with Option:

#[derive(FromMeta)]
pub struct Example {
    do_things: Option<Word>
}

Note that unlike (), the implementation of FromMeta for Word would capture the span of the path:

#[example(do_things)]
//        ^^^^^^^^^

This enables useful attachment of diagnostics to the word.

Open Questions

  1. Should we rename Flag in place and take the breaking change?
  2. Should we have a similar utility for bool, maybe called Toggle?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant