I want to do something like this:
enum Foo {
Empty,
Single(String),
Multiple(Vec<String>),
}
fn convert(xs: Vec<String>) -> Foo {
match xs {
[] => Foo::Empty,
[x] => Foo::Single(x),
xs => Foo::Multiple(xs),
}
}
The problems:
- A
Vec
is not an array, so the above code wouldn't compile. - Using slice would require cloning.