diff --git a/src/array/utf8/mod.rs b/src/array/utf8/mod.rs index b6b56e14ccb..69c5af6e8f0 100644 --- a/src/array/utf8/mod.rs +++ b/src/array/utf8/mod.rs @@ -486,8 +486,7 @@ impl Utf8Array { P: AsRef, I: TrustedLen>, { - // soundness: I is `TrustedLen` - unsafe { Self::from_trusted_len_iter_unchecked(iterator) } + MutableUtf8Array::::from_trusted_len_iter(iterator).into() } /// Creates a [`Utf8Array`] from an falible iterator of trusted length. @@ -512,8 +511,7 @@ impl Utf8Array { P: AsRef, I: TrustedLen, E>>, { - // soundness: I: TrustedLen - unsafe { Self::try_from_trusted_len_iter_unchecked(iter) } + MutableUtf8Array::::try_from_trusted_len_iter(iter).map(|x| x.into()) } /// Alias for `new` diff --git a/tests/it/array/utf8/mod.rs b/tests/it/array/utf8/mod.rs index fc55ebccdec..c6a0acec03f 100644 --- a/tests/it/array/utf8/mod.rs +++ b/tests/it/array/utf8/mod.rs @@ -215,3 +215,21 @@ fn into_mut_4() { let array = Utf8Array::::new(DataType::Utf8, offsets, values, validity); assert!(array.into_mut().is_right()); } + +#[test] +fn rev_iter() { + let array = Utf8Array::::from(&[Some("hello"), Some(" "), None]); + + assert_eq!( + array.into_iter().rev().collect::>(), + vec![None, Some(" "), Some("hello")] + ); +} + +#[test] +fn iter_nth() { + let array = Utf8Array::::from(&[Some("hello"), Some(" "), None]); + + assert_eq!(array.iter().nth(1), Some(Some(" "))); + assert_eq!(array.iter().nth(10), None); +} diff --git a/tests/it/array/utf8/mutable.rs b/tests/it/array/utf8/mutable.rs index 8ee76476cbb..80cc24ca3c8 100644 --- a/tests/it/array/utf8/mutable.rs +++ b/tests/it/array/utf8/mutable.rs @@ -141,3 +141,29 @@ fn test_extend_values() { assert_eq!(array.offsets().as_slice(), &[0, 2, 7, 12, 17]); assert_eq!(array.validity(), None,); } + +#[test] +fn test_extend() { + let mut array = MutableUtf8Array::::new(); + + array.extend([Some("hi"), None, Some("there"), None].into_iter()); + + let array: Utf8Array = array.into(); + + assert_eq!( + array, + Utf8Array::::from([Some("hi"), None, Some("there"), None]) + ); +} + +#[test] +fn as_arc() { + let mut array = MutableUtf8Array::::new(); + + array.extend([Some("hi"), None, Some("there"), None].into_iter()); + + assert_eq!( + Utf8Array::::from([Some("hi"), None, Some("there"), None]), + array.as_arc().as_ref() + ); +}