-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Auto-detect
FromStr
, TryFrom<&OsStr>
, etc., in clap_derive
Clap has several different options for parsing strings into values: `try_from_str`, `try_from_os_str`, `from_str`, `from_os_str`, each corresponding to a different way of parsing strings. This patch adds a new option: `auto`, which auto-detects which parsing traits a type supports, out of `clap::ArgEnum`, `TryFrom<&OsStr>`, `FromStr`, `TryFrom<&str>`, `From<&OsStr>`, and `From<&str>`, and selects the best one to use automatically. This way, users can use any type which implements any of these traits, and clap_derive automatically figures out what to do. It's implemented via [autoref specialization], a limited form of specialization which only works in macro contexts, but that turns out to be enough for clap_derive. This changes the default to `auto`. The previous default `try_from_str` uses the `FromStr` trait. `auto` auto-detects `FromStr`, so this is a mostly backwards-compatible change. [autoref specialization]: http://lukaskalbertodt.github.io/2019/12/05/generalized-autoref-based-specialization.html
- Loading branch information
1 parent
b8b112b
commit 1805a97
Showing
11 changed files
with
716 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.