#Using IntoIter<Item = S> where S = AsRef<OsStr> is confusing the typer, and myself

3 messages · Page 1 of 1 (latest)

worldly cloak
#

I have a function defined as follows:

pub fn run<I, S>(command: S, args: I) -> Result<Output>
where
    I: IntoIterator<Item = S>,
    S: AsRef<OsStr>,
{

And I am trying to call it as such:

run(prog, [OsStr::new("a"), OsStr::new("b")]);

And the compiler is complaining that:

  | |_____________^ expected `&str`, found `&OsStr`
   |
   = note: expected reference `&str`
              found reference `&std::ffi::OsStr`

Why is it deducing &str ?

pseudo grove
#

Probably because command is &str, which fills in S.

worldly cloak
#

You're right, and I totally missed that :/ My nose was too close. prog is the &str.

But would there be way to remove that coupling, other than declating a ndifferent typeparam (because I tried that and it works).