How to correctly implement FromStr to get list of strings?

I'm using crate structopt. I want to implement a parameter which has a list of elements.
I've tried to implement it in the following way:

struct Foo(Vec<String>);

impl FromStr for Foo {
    type Err = Utf8Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(s.split(",").map(|s| s.to_string()).collect())
    }
}

But Rust complains with following error message:

error[E0277]: a value of type `options::Foo` cannot be built from an iterator over elements of type `std::string::String`
  --> zarlib/src/options.rs:15:12
   |
15 |         Ok(s.split(",").map(|s| s.to_string()).collect())
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ value of type `options::Foo` cannot be built from `std::iter::Iterator<Item=std::string::String>`
   |
   = help: the trait `std::iter::FromIterator<std::string::String>` is not implemented for `options::Foo`

How do I solve this?

It's because the Self here is Foo, not Vec<String>.

struct Foo(Vec<String>);

impl FromStr for Foo {
    type Err = Utf8Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Foo(s.split(",").map(|s| s.to_string()).collect()))
    }
}

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.