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

Improved docs for BooleanArray #1083

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
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
78 changes: 0 additions & 78 deletions src/array/boolean/from.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,13 @@
use std::iter::FromIterator;

use crate::trusted_len::TrustedLen;

use super::{BooleanArray, MutableBooleanArray};

impl<P: AsRef<[Option<bool>]>> From<P> for BooleanArray {
/// Creates a new [`BooleanArray`] out of a slice of Optional `bool`.
fn from(slice: P) -> Self {
MutableBooleanArray::from(slice).into()
}
}

impl BooleanArray {
/// Creates a new [`BooleanArray`] from an [`TrustedLen`] of `bool`.
#[inline]
pub fn from_trusted_len_values_iter<I: TrustedLen<Item = bool>>(iterator: I) -> Self {
MutableBooleanArray::from_trusted_len_values_iter(iterator).into()
}

/// Creates a new [`BooleanArray`] from an [`TrustedLen`] of `bool`.
/// Use this over [`BooleanArray::from_trusted_len_iter`] when the iterator is trusted len
/// but this crate does not mark it as such.
/// # 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<I: Iterator<Item = bool>>(
iterator: I,
) -> Self {
MutableBooleanArray::from_trusted_len_values_iter_unchecked(iterator).into()
}

/// Creates a new [`BooleanArray`] from a slice of `bool`.
#[inline]
pub fn from_slice<P: AsRef<[bool]>>(slice: P) -> Self {
MutableBooleanArray::from_slice(slice).into()
}

/// Creates a [`BooleanArray`] from an iterator of trusted length.
/// Use this over [`BooleanArray::from_trusted_len_iter`] when the iterator is trusted len
/// but this crate does not mark it as such.
/// # 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: std::borrow::Borrow<bool>,
I: Iterator<Item = Option<P>>,
{
MutableBooleanArray::from_trusted_len_iter_unchecked(iterator).into()
}

/// Creates a [`BooleanArray`] from a [`TrustedLen`].
#[inline]
pub fn from_trusted_len_iter<I, P>(iterator: I) -> Self
where
P: std::borrow::Borrow<bool>,
I: TrustedLen<Item = Option<P>>,
{
MutableBooleanArray::from_trusted_len_iter(iterator).into()
}

/// Creates a [`BooleanArray`] 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: std::borrow::Borrow<bool>,
I: Iterator<Item = Result<Option<P>, E>>,
{
Ok(MutableBooleanArray::try_from_trusted_len_iter_unchecked(iterator)?.into())
}

/// Creates a [`BooleanArray`] from a [`TrustedLen`].
#[inline]
pub fn try_from_trusted_len_iter<E, I, P>(iterator: I) -> Result<Self, E>
where
P: std::borrow::Borrow<bool>,
I: TrustedLen<Item = Result<Option<P>, E>>,
{
Ok(MutableBooleanArray::try_from_trusted_len_iter(iterator)?.into())
}
}

impl<Ptr: std::borrow::Borrow<Option<bool>>> FromIterator<Ptr> for BooleanArray {
fn from_iter<I: IntoIterator<Item = Ptr>>(iter: I) -> Self {
MutableBooleanArray::from_iter(iter).into()
Expand Down
17 changes: 0 additions & 17 deletions src/array/boolean/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,6 @@ impl<'a> IntoIterator for &'a BooleanArray {
}
}

impl<'a> BooleanArray {
/// Returns an iterator over the optional values of this [`BooleanArray`].
#[inline]
pub fn iter(&'a self) -> ZipValidity<'a, bool, BitmapIter<'a>> {
zip_validity(
self.values().iter(),
self.validity.as_ref().map(|x| x.iter()),
)
}

/// Returns an iterator over the values of this [`BooleanArray`]
#[inline]
pub fn values_iter(&'a self) -> BitmapIter<'a> {
self.values().iter()
}
}

impl<'a> IntoIterator for &'a MutableBooleanArray {
type Item = Option<bool>;
type IntoIter = ZipValidity<'a, bool, BitmapIter<'a>>;
Expand Down
Loading