Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Utf8 add unchecked trusted_len_values_iter (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 24, 2021
1 parent 7f2c5bd commit c979dbf
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,26 @@ impl<O: Offset> MutableUtf8Array<O> {
unsafe { Self::from_trusted_len_iter_unchecked(iterator) }
}

/// Creates a [`MutableUtf8Array`] from an iterator of trusted length of `&str`.
/// # Safety
/// The iterator must be [`TrustedLen`](https://doc.rust-lang.org/std/iter/trait.TrustedLen.html).
/// I.e. that `size_hint().1` correctly reports its length.
#[inline]
pub unsafe fn from_trusted_len_values_iter_unchecked<T: AsRef<str>, I: Iterator<Item = T>>(
iterator: I,
) -> Self {
let (offsets, values) = unsafe { trusted_len_values_iter(iterator) };
// soundness: T is AsRef<str>
Self::from_data_unchecked(Self::default_data_type(), offsets, values, None)
}

/// Creates a new [`Utf8Array`] from a [`TrustedLen`] of `&str`.
#[inline]
pub fn from_trusted_len_values_iter<T: AsRef<str>, I: TrustedLen<Item = T>>(
iterator: I,
) -> Self {
// soundness: I is `TrustedLen`
let (offsets, values) = unsafe { trusted_len_values_iter(iterator) };
// soundness: T is AsRef<str>
unsafe { Self::from_data_unchecked(Self::default_data_type(), offsets, values, None) }
unsafe { Self::from_trusted_len_values_iter_unchecked(iterator) }
}

/// Creates a new [`MutableUtf8Array`] from an iterator.
Expand Down

0 comments on commit c979dbf

Please sign in to comment.