Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EcoVec::extend_from_trusted public #39

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,16 @@ impl<T> EcoVec<T> {
impl<T: Clone> EcoVec<T> {
/// Clones and pushes all elements in a trusted-len iterator to the vector.
///
/// The iterator must produce exactly `count` items.
unsafe fn extend_from_trusted<I>(&mut self, count: usize, iter: I)
/// # Safety
/// `ExactSizeIterator::len` must return the exact length of the iterator.
pub unsafe fn extend_from_trusted<I>(&mut self, iter: I)
where
I: IntoIterator<Item = T>,
I::IntoIter: ExactSizeIterator,
{
let iter = iter.into_iter();
let count = iter.len();

if count == 0 {
return;
}
Expand Down Expand Up @@ -965,7 +970,7 @@ impl<T: Clone, const N: usize> From<[T; N]> for EcoVec<T> {
let mut vec = Self::new();
unsafe {
// Safety: Array's IntoIter implements `TrustedLen`.
vec.extend_from_trusted(array.len(), array);
vec.extend_from_trusted(array);
}
vec
}
Expand All @@ -977,7 +982,7 @@ impl<T: Clone> From<Vec<T>> for EcoVec<T> {
let mut vec = Self::new();
unsafe {
// Safety: Vec's IntoIter implements `TrustedLen`.
vec.extend_from_trusted(other.len(), other);
vec.extend_from_trusted(other);
}
vec
}
Expand Down
Loading