Closed nyarly closed 6 months ago
I'm not sure if it isn't too specific for your use case to be added to the library :thinking: .
I have a bit of time in the two weeks starting next week and plan to update my github projects then. So I will come back to this in 1-2 weeks.
I thought about it a bit more but I think it's too specific to your use case/out of scope.
You can always add a simple extension trait like
trait Vec1Ext<T> {
fn into_only(self) -> Option<T>;
}
impl<T> Vec1Ext<T> for Vec1<T> {
fn into_only(self) -> Option<T> {
....
}
}
and then e.g. use crate::utils::Vec1Ext as _
I have a use case where I have a vec1 and it may have exactly one element - in some cases it's an error for there to be more than one element.
Currently I have:
I'd love to have:
that would consume a vec1 with only one element, but otherwise return None. (Alternatively, it could return a Result with Err(MoreThanOne)). The above would become
or just