Why doesn't my implementation of TryFrom<Vec<T>> cover TryFrom<Vec<String>>?

Viewed 202

When I try to compile this line, opt.positionals = Positionals::try_from(opt.args).unwrap(); I'm getting an error about a trait not being implement. This trait should be implemented though generically as I have TryFrom<Vec<T>>

Here is the error,

error[E0277]: the trait bound `Positionals: TryFrom<Vec<String>>` is not satisfied
  --> bin/seq.rs:83:20
   |
83 |     opt.positionals = Positionals::try_from(opt.args).unwrap();
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TryFrom<Vec<String>>` is not implemented for `Positionals`
   |
   = help: the following implementations were found:
             <Positionals as TryFrom<Vec<T>>>

And here is my implementation of the trait,

use std::convert::TryFrom;
impl<T: Debug + AsRef<String> + Into<String> + Clone> TryFrom<Vec<T>> for Positionals {

Why doesn't my implementation of TryFrom<Vec<T>> cover the concrete TryFrom<Vec<String>> and how can I remedy this problem?

1 Answers

String does not implement AsRef<String>. You could use AsRef<str> or Borrow<String> instead.

Related