impl TryFrom for vector references for AtLeastOne (#2578)
Co-authored-by: Conrado Gouvea <conrado@zfnd.org>
This commit is contained in:
parent
0cc773f4b8
commit
4eb0344f01
|
@ -91,6 +91,23 @@ impl<T> TryFrom<Vec<T>> for AtLeastOne<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> TryFrom<&Vec<T>> for AtLeastOne<T>
|
||||||
|
where
|
||||||
|
T: Clone,
|
||||||
|
{
|
||||||
|
type Error = SerializationError;
|
||||||
|
|
||||||
|
fn try_from(vec: &Vec<T>) -> Result<Self, Self::Error> {
|
||||||
|
if vec.is_empty() {
|
||||||
|
Err(SerializationError::Parse("expected at least one item"))
|
||||||
|
} else {
|
||||||
|
Ok(AtLeastOne {
|
||||||
|
inner: vec.to_vec(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> TryFrom<&[T]> for AtLeastOne<T>
|
impl<T> TryFrom<&[T]> for AtLeastOne<T>
|
||||||
where
|
where
|
||||||
T: Clone,
|
T: Clone,
|
||||||
|
|
Loading…
Reference in New Issue