@@ -984,34 +984,45 @@ impl<T: Element> PyArray<T, Ix1> {
984
984
/// # Example
985
985
/// ```
986
986
/// 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( ));
991
991
/// assert_eq!(pyarray.readonly().as_slice().unwrap(), &[1, 2, 3, 4, 5]);
992
992
/// });
993
993
/// ```
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)
997
1004
}
998
1005
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`].
1001
1007
///
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,
1003
1009
/// this method can allocate memory multiple time, which can hurt performance.
1004
1010
///
1005
1011
/// # Example
1012
+ ///
1006
1013
/// ```
1007
1014
/// 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]);
1012
1020
/// });
1013
1021
/// ```
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
+ {
1015
1026
let data = iter. into_iter ( ) . collect :: < Vec < _ > > ( ) ;
1016
1027
data. into_pyarray ( py)
1017
1028
}
0 commit comments