mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-06-10 03:28:18 +02:00
compiler/rust/smallvec: Implement FromIterator and From<[T; N]>
Reviewed-by: Mel Henning <mhenning@darkrefraction.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41941>
This commit is contained in:
parent
bb1695e172
commit
96659a502f
1 changed files with 22 additions and 0 deletions
|
|
@ -138,3 +138,25 @@ impl<T> From<Vec<T>> for SmallVec<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, const N: usize> From<[T; N]> for SmallVec<T> {
|
||||
fn from(i: [T; N]) -> SmallVec<T> {
|
||||
i.into_iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> FromIterator<T> for SmallVec<T> {
|
||||
fn from_iter<I>(iter: I) -> Self
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
{
|
||||
let mut iter = iter.into_iter();
|
||||
let Some(x) = iter.next() else {
|
||||
return SmallVec::None;
|
||||
};
|
||||
let Some(y) = iter.next() else {
|
||||
return SmallVec::One(x);
|
||||
};
|
||||
SmallVec::Many([x, y].into_iter().chain(iter).collect())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue