dimforge / dimforge/nalgebra

`from_iter` implementation may run indefinitely

Open
#1,391 8 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

Creating a vector or a matrix with the `from_iter` method may run indefinitely. I don't think this is the expected behaviour. I.e.
```rust
#[test]
fn test_nalgebra_finishes() {
use nalgebra::DVector; // 0.32.5
use std::iter;
// Runs indefinitely
let _vector = DVector::from_iterator(70, iter::from_fn(|| Some(1)));
}
```
will never finish. ([Playground](https://play.rust-lang.org/?version=stable&mode=release&edition=2021))

I think it would make sense to either:

1. Limit the iterator automatically and ignore the remaining entries.
2. Panic if the iterator has elements remaining if the capacity has been reached.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.