Closed duesee closed 1 year ago
What is the best way to construct a NonEmptyVec?
NonEmptyVec
Currently, we have ...
impl<T> From<T> for NonEmptyVec<T> { fn from(value: T) -> Self { NonEmptyVec(vec![value]) } } impl<T> TryFrom<Vec<T>> for NonEmptyVec<T> { type Error = NonEmptyVecError; fn try_from(inner: Vec<T>) -> Result<Self, Self::Error> { Self::validate(&inner)?; Ok(Self(inner)) } }
However, this could be confusing. Try for yourself: What is the difference between NonEmptyVec::from(vec![]) and NonEmptyVec::try_from(vec![])? :-)
NonEmptyVec::from(vec![])
NonEmptyVec::try_from(vec![])
References:
I think this is fine for now.
What is the best way to construct a
NonEmptyVec
?Currently, we have ...
However, this could be confusing. Try for yourself: What is the difference between
NonEmptyVec::from(vec![])
andNonEmptyVec::try_from(vec![])
? :-)References: