Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type IntoIter is private #1365

Closed
ivan-aksamentov opened this issue Mar 5, 2024 · 2 comments · Fixed by #1370
Closed

Type IntoIter is private #1365

ivan-aksamentov opened this issue Mar 5, 2024 · 2 comments · Fixed by #1370
Labels

Comments

@ivan-aksamentov
Copy link

ivan-aksamentov commented Mar 5, 2024

The type IntoIter implemented in #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:

mod iterators;

The sibling types Iter and IterMut are exposed additionally in lib.rs

use crate::iterators::{ElementsBase, ElementsBaseMut, Iter, IterMut};

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:

  • expose IntoIter publicly to solve this problem directly
  • refactor public exports to avoid unnecessary complexity and prevent this kind of bugs from happening again
  • add tests validating public interface of the library; require these tests to be added along with the new functionality in PRs affecting public interface
@ivan-aksamentov ivan-aksamentov changed the title Trait IntoIter is private Type IntoIter is private Mar 5, 2024
@bluss
Copy link
Member

bluss commented Mar 5, 2024

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

@bluss bluss added the bug label Mar 6, 2024
@bluss
Copy link
Member

bluss commented Mar 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants