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

Change FromArgs::from_args to accept AsRef<str> #160

Open
poliorcetics opened this issue Apr 11, 2023 · 0 comments
Open

Change FromArgs::from_args to accept AsRef<str> #160

poliorcetics opened this issue Apr 11, 2023 · 0 comments

Comments

@poliorcetics
Copy link

Current the function is defined as:

    fn from_args(command_name: &[&str], args: &[&str]) -> Result<Self, EarlyExit>;

This could be changed to:

    fn from_args<T, U>(command_name: &[T], args: &[U]) -> Result<Self, EarlyExit> where T: AsRef<str>, U: AsRef<str>;

I think this is backward-incompatible because of type deductions that could now fail.

FromArgs::redact_arg_values should also be updated if this is done.

Why ?

Current when getting arguments from std::env::args_os(), several collects and transformations are necessary to go from Iterator<Item = OsStr> to &[&str], which is a little sad.

  1. OsStr to String (to_string_lossy, to_string + unwrap)
  2. Collect to a vec of String
  3. Iter, as_str
  4. Collect to a vec of &str

With the change proposed in this issue, steps 3 and 4 would become unnecessary

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

No branches or pull requests

1 participant