@@ -984,34 +984,45 @@ impl<T: Element> PyArray<T, Ix1> {
984984 /// # Example
985985 /// ```
986986 /// use numpy::PyArray;
987- /// use std::collections::BTreeSet ;
988- /// let vec = vec![1, 2, 3, 4, 5];
989- /// pyo3:: Python::with_gil(|py| {
990- /// let pyarray = PyArray::from_exact_iter(py, vec.iter ().map(|&x| x ));
987+ /// use pyo3::Python ;
988+ ///
989+ /// Python::with_gil(|py| {
990+ /// let pyarray = PyArray::from_exact_iter(py, [1, 2, 3, 4, 5].into_iter ().copied( ));
991991 /// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[1, 2, 3, 4, 5]);
992992 /// });
993993 /// ```
994- pub fn from_exact_iter ( py : Python < ' _ > , iter : impl ExactSizeIterator < Item = T > ) -> & Self {
995- let data = iter. collect :: < Box < [ _ ] > > ( ) ;
996- data. into_pyarray ( py)
994+ #[ deprecated(
995+ note = "`from_exact_iter` is deprecated as it does not provide any benefit over `from_iter`."
996+ ) ]
997+ #[ inline( always) ]
998+ pub fn from_exact_iter < I > ( py : Python < ' _ > , iter : I ) -> & Self
999+ where
1000+ I : IntoIterator < Item = T > ,
1001+ I :: IntoIter : ExactSizeIterator ,
1002+ {
1003+ Self :: from_iter ( py, iter)
9971004 }
9981005
999- /// Construct one-dimension PyArray from a type which implements
1000- /// [`IntoIterator`](https://doc.rust-lang.org/std/iter/trait.IntoIterator.html).
1006+ /// Construct one-dimension PyArray from a type which implements [`IntoIterator`].
10011007 ///
1002- /// If no reliable [`size_hint`](https://doc.rust-lang.org/std/iter/trait. Iterator.html#method. size_hint) is available,
1008+ /// If no reliable [`size_hint`][ Iterator:: size_hint] is available,
10031009 /// this method can allocate memory multiple time, which can hurt performance.
10041010 ///
10051011 /// # Example
1012+ ///
10061013 /// ```
10071014 /// use numpy::PyArray;
1008- /// let set: std::collections::BTreeSet<u32> = [4, 3, 2, 5, 1].into_iter().cloned().collect();
1009- /// pyo3::Python::with_gil(|py| {
1010- /// let pyarray = PyArray::from_iter(py, set);
1011- /// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[1, 2, 3, 4, 5]);
1015+ /// use pyo3::Python;
1016+ ///
1017+ /// Python::with_gil(|py| {
1018+ /// let pyarray = PyArray::from_iter(py, "abcde".chars().map(u32::from));
1019+ /// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[97, 98, 99, 100, 101]);
10121020 /// });
10131021 /// ```
1014- pub fn from_iter ( py : Python < ' _ > , iter : impl IntoIterator < Item = T > ) -> & Self {
1022+ pub fn from_iter < I > ( py : Python < ' _ > , iter : I ) -> & Self
1023+ where
1024+ I : IntoIterator < Item = T > ,
1025+ {
10151026 let data = iter. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
10161027 data. into_pyarray ( py)
10171028 }
0 commit comments