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

Commit

Permalink
Fixes to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed May 27, 2022
1 parent bbe7209 commit b8c151d
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 268 deletions.
2 changes: 1 addition & 1 deletion src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl<O: Offset> BinaryArray<O> {
Self::try_new_unchecked(data_type, offsets, values, validity).unwrap()
}

/// Alias for [`new_unchecked`]
/// Alias for [`Self::new_unchecked`]
/// # Safety
/// This function is unsafe iff:
/// * the offsets are not monotonically increasing
Expand Down
2 changes: 1 addition & 1 deletion src/array/equal/utf8.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::array::{Array, Offset, Utf8Array};
use crate::array::{Offset, Utf8Array};

pub(super) fn equal<O: Offset>(lhs: &Utf8Array<O>, rhs: &Utf8Array<O>) -> bool {
lhs.data_type() == rhs.data_type() && lhs.len() == rhs.len() && lhs.iter().eq(rhs.iter())
Expand Down
2 changes: 1 addition & 1 deletion src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl FixedSizeBinaryArray {
.get_unchecked(i * self.size..(i + 1) * self.size)
}

/// Returns a new [`FixedSizeBinary`] with a different logical type.
/// Returns a new [`FixedSizeBinaryArray`] with a different logical type.
/// This is `O(1)`.
/// # Panics
/// Panics iff the data_type is not supported for the physical type.
Expand Down
79 changes: 0 additions & 79 deletions src/array/utf8/from.rs
Original file line number Diff line number Diff line change
@@ -1,88 +1,9 @@
use std::iter::FromIterator;

use crate::array::Offset;
use crate::trusted_len::TrustedLen;

use super::{MutableUtf8Array, Utf8Array};

impl<O: Offset> Utf8Array<O> {
/// Creates a new [`Utf8Array`] from a slice of `&str`.
/// This is a convenience method that just calls [`Self::from_trusted_len_values_iter`].
#[inline]
pub fn from_slice<T: AsRef<str>, P: AsRef<[T]>>(slice: P) -> Self {
Self::from_trusted_len_values_iter(slice.as_ref().iter())
}

/// Creates a new [`Utf8Array`] from a slice of `&str`.
// Note: this can't be `impl From` because Rust does not allow double `AsRef` on it.
pub fn from<T: AsRef<str>, P: AsRef<[Option<T>]>>(slice: P) -> Self {
Self::from_trusted_len_iter(slice.as_ref().iter().map(|x| x.as_ref()))
}

/// 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 {
MutableUtf8Array::<O>::from_trusted_len_values_iter(iterator).into()
}

/// Creates a new [`Utf8Array`] from a [`Iterator`] of `&str`.
pub fn from_iter_values<T: AsRef<str>, I: Iterator<Item = T>>(iterator: I) -> Self {
MutableUtf8Array::<O>::from_iter_values(iterator).into()
}
}

impl<O: Offset> Utf8Array<O> {
/// Creates a [`Utf8Array`] from an iterator of trusted length.
/// # 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_iter_unchecked<I, P>(iterator: I) -> Self
where
P: AsRef<str>,
I: Iterator<Item = Option<P>>,
{
MutableUtf8Array::<O>::from_trusted_len_iter_unchecked(iterator).into()
}

/// Creates a [`Utf8Array`] from an iterator of trusted length.
#[inline]
pub fn from_trusted_len_iter<I, P>(iterator: I) -> Self
where
P: AsRef<str>,
I: TrustedLen<Item = Option<P>>,
{
// soundness: I is `TrustedLen`
unsafe { Self::from_trusted_len_iter_unchecked(iterator) }
}

/// Creates a [`Utf8Array`] from an falible iterator of trusted length.
/// # 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 try_from_trusted_len_iter_unchecked<E, I, P>(iterator: I) -> Result<Self, E>
where
P: AsRef<str>,
I: IntoIterator<Item = Result<Option<P>, E>>,
{
MutableUtf8Array::<O>::try_from_trusted_len_iter_unchecked(iterator).map(|x| x.into())
}

/// Creates a [`Utf8Array`] from an fallible iterator of trusted length.
#[inline]
pub fn try_from_trusted_len_iter<E, I, P>(iter: I) -> Result<Self, E>
where
P: AsRef<str>,
I: TrustedLen<Item = Result<Option<P>, E>>,
{
// soundness: I: TrustedLen
unsafe { Self::try_from_trusted_len_iter_unchecked(iter) }
}
}

impl<O: Offset, P: AsRef<str>> FromIterator<Option<P>> for Utf8Array<O> {
#[inline]
fn from_iter<I: IntoIterator<Item = Option<P>>>(iter: I) -> Self {
Expand Down
17 changes: 1 addition & 16 deletions src/array/utf8/iterator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::bitmap::utils::{zip_validity, ZipValidity};
use crate::bitmap::utils::ZipValidity;
use crate::{array::Offset, trusted_len::TrustedLen};

use super::Utf8Array;
Expand Down Expand Up @@ -74,19 +74,4 @@ impl<'a, O: Offset> IntoIterator for &'a Utf8Array<O> {
}
}

impl<'a, O: Offset> Utf8Array<O> {
/// Returns an iterator of `Option<&str>`
pub fn iter(&'a self) -> ZipValidity<'a, &'a str, Utf8ValuesIter<'a, O>> {
zip_validity(
Utf8ValuesIter::new(self),
self.validity.as_ref().map(|x| x.iter()),
)
}

/// Returns an iterator of `&str`
pub fn values_iter(&'a self) -> Utf8ValuesIter<'a, O> {
Utf8ValuesIter::new(self)
}
}

unsafe impl<O: Offset> TrustedLen for Utf8ValuesIter<'_, O> {}
Loading

0 comments on commit b8c151d

Please sign in to comment.