rust-ndarray / ndarray

ndarray: an N-dimensional array with array views, multidimensional slicing, and efficient operations
https://docs.rs/ndarray/
Apache License 2.0
3.43k stars 295 forks source link

Type `IntoIter` is private #1365

Closed ivan-aksamentov closed 4 months ago

ivan-aksamentov commented 4 months ago

The type IntoIter implemented in https://github.com/rust-ndarray/ndarray/pull/986 is not exposed publicly, which makes it difficult or impossible to implement IntoIterator trait for custom types wrapping ndarray:

use ndarray::iterators::IntoIter; // Module `iterators` is private

pub struct Foo {
  array: Array1<i32>,
}

impl IntoIterator for Foo {
  type Item = i32;
  type IntoIter = IntoIter<i32, Ix1>; // `IntoIter` is private
  fn into_iter(self) -> Self::IntoIter {
    self.array.into_iter()
  }
}

The type is private in it's own module, re-exported publicly from module iterators, however module iterators itself is not public in lib.rs: https://github.com/rust-ndarray/ndarray/blob/97ecc0db70d53a1119c7b03149fcd7207d4580bd/src/lib.rs#L191

The sibling types Iter and IterMut are exposed additionally in lib.rs https://github.com/rust-ndarray/ndarray/blob/97ecc0db70d53a1119c7b03149fcd7207d4580bd/src/lib.rs#L146

I believe that the reason why the author of the PR missed this is the unnecessary spaghetti of re-exports. There seem to be no particular pattern in place. Why is this complexity needed? How it can be improved?

Proposed changes:

bluss commented 4 months ago

It should be in https://docs.rs/ndarray/latest/ndarray/iter/index.html and if it is not, it is a bug

bluss commented 4 months ago

I don't think it's impossible - <Array1<i32> as IntoIterator>::IntoIter should be available to you?