argh icon indicating copy to clipboard operation
argh copied to clipboard

Change `FromArgs::from_args` to accept `AsRef<str>`

Open poliorcetics opened this issue 1 year ago • 0 comments

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

poliorcetics avatar Apr 11 '23 13:04 poliorcetics