Skip to content

Add require_ident to Path#1496

Merged
dtolnay merged 1 commit intodtolnay:masterfrom
Fancyflame:master
Sep 10, 2023
Merged

Add require_ident to Path#1496
dtolnay merged 1 commit intodtolnay:masterfrom
Fancyflame:master

Conversation

@Fancyflame
Copy link
Copy Markdown
Contributor

@Fancyflame Fancyflame commented Sep 2, 2023

Parsing options inside a list is very commonplace:

#[my_attr(path(linux = "path/to/file")]
          ^^^^ ^^^^^
          Here is our options

Although we have get_ident, we (at least I) would not like to handle None. Just like require_path, require_list and require_key_value, which I love.

match &*path.require_ident()?.to_string() {
    "linux" => { ... }
    "windows" => { ... }
    "macos" => { ... }
    other => return Err(Error::new(
        Span::call_site(),
        format!("platform `{other}` not supported")
    ))
}

Copy link
Copy Markdown
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks!

@dtolnay dtolnay merged commit 07a89dd into dtolnay:master Sep 10, 2023
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.

2 participants