Use OneOrMany::One when explicitly converting from single item Vec
@@ -83,10 +83,14 @@ impl<T> From<T> for OneOrMany<T> {
}
impl<T> From<Vec<T>> for OneOrMany<T> {
- fn from(other: Vec<T>) -> Self {
+ fn from(mut other: Vec<T>) -> Self {
+ if other.len() == 1 {
+ Self::One(other.pop().expect("infallible"))
+ } else {
Self::Many(other)
}
}
+}
impl<T> From<OneOrMany<T>> for Vec<T> {
fn from(other: OneOrMany<T>) -> Self {
