DEV Community

Discussion on: YARIT: Yet Another Rust Iterators Tutorial

Collapse
 
x10an14 profile image
x10an14

Hi! I was helped by your post in my stumbling foray into implementing .zip() on my structs which are basically just wrappers around vectors!

Thanks a lot for your insightful post!
It's obvious that I've yet got much to understand on the topic of traits and lifetimes in Rust.

I'm struggling to get my code to work though - I've purposefully only implemented the non-consuming iterators and wrappers, yet I end up with a compile error where my next(&mut self) -> Option<Self::Item> functions fail because self.iter.next() returns Option<&Self::Item> and not Option<Self::Item>.

Is this similar to something you've encountered?
PS: My source code for reference: gitlab.com/x10an14/n-dim-ttt

Collapse
 
dandyvica profile image
Dandy Vica

Hi,

Sorry but I missed your comment. Could you maybe post a link on the Rust playground, if it's not too late ?

Collapse
 
x10an14 profile image
x10an14

This should illustrate my intent =)
It is important for me to be able to use some syntax like .zip().map().

play.rust-lang.org/?version=stable...

Thread Thread
 
dandyvica profile image
Dandy Vica

Are you sure it's not related to the first error 0658 ?

Thread Thread
 
x10an14 profile image
x10an14

I dunno, I thought the error message I had was that it ended up in an infinite recursive loop due to somehow making the iterator's next() function refer to itself.

It's unfortunately a bit too long for me to remember.

I know that I get an overflow when I try

[2020-03-12 20:24:38] 0 x10an14@x10-desktop:~/gitlab/n-dim-ttt                                                                                                                                                                                              (master=)
-> $ cargo run -- -i 4 
warning: unused import: `cmp::max`
 --> src/game_objects.rs:4:11
  |
4 | use std::{cmp::max, collections::HashSet};
  |           ^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unused variable: `vector12`
  --> src/game_objects.rs:28:13
   |
28 |         let vector12: Vector = Vector::new(&coordinates[0], &coordinates[1]);
   |             ^^^^^^^^ help: consider prefixing with an underscore: `_vector12`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: function cannot return without recursing
  --> src/game_objects/structs.rs:70:5
   |
70 |     fn next(&mut self) -> Option<Self::Item> {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
71 |         self.next()
   |         ----------- recursive call site
   |
   = note: `#[warn(unconditional_recursion)]` on by default
   = help: a `loop` may express intention better if this is on purpose

warning: function cannot return without recursing
   --> src/game_objects/structs.rs:124:5
    |
124 |     fn next(&mut self) -> Option<Self::Item> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
125 |         self.next()
    |         ----------- recursive call site
    |
    = help: a `loop` may express intention better if this is on purpose

    Finished dev [unoptimized + debuginfo] target(s) in 0.02s
     Running `target/debug/n-dim-ttt -i 4`

thread 'main' has overflowed its stack
fatal runtime error: stack overflow
Aborted
[2020-03-12 20:24:48] 134 x10an14@x10-desktop:~/gitlab/n-dim-ttt                                                                                                                                                                                            (master=)
-> $ 

at git checkout 5f7eea2ac51593cf257c62f9a7c25f331ff7226ain my earlier mentioned gitlab git repo.