Linked Questions

11 votes
1 answer
17k views

I'm having difficulty with lifetimes when trying to create a mutable iterator in safe Rust. Here is what I have reduced my problem to: struct DataStruct<T> { inner: Box<[T]>, } pub ...
Barnaby Dalton's user avatar
4 votes
2 answers
1k views

I am trying to implement a simple lookup iterator: pub struct LookupIterMut<'a, D> { data : &'a mut [D], indices : &'a [usize], i: usize } impl<'a, D> Iterator for ...
milck's user avatar
  • 712
5 votes
1 answer
1k views

I want to design a toy container class with support for mutable iterators, but I'm having trouble sorting out the lifetimes of the iterator and its reference to the container. I've tried to create a ...
avl_sweden's user avatar
2 votes
1 answer
814 views

I'd like to create a struct that holds a slice, and can return references to items in that slice. So far, I've been able to do this: pub struct Stride<'a> { items: &'a [f32], } impl<...
awelkie's user avatar
  • 2,692
1 vote
0 answers
1k views

How do I scope the lifetime for a function that returns a reference to a member variable? The reference will be valid as long as the struct is alive. Here is an example where one might want this: ...
charmoniumQ's user avatar
  • 5,583
4 votes
0 answers
438 views

I have a slice of items and a slice of indices into the first slice, essentially giving me a sub-group of items that I want to modify. To iterate over the items and manipulate them I can create the ...
Michael Mauderer's user avatar
0 votes
1 answer
289 views

I am trying to write a mutable iterator over a vector, but I am unable to figure out what the compiler is trying to tell me. Here is my implementation struct IterMut<'a> { vec: &'a mut ...
rozina's user avatar
  • 4,260
0 votes
1 answer
190 views

I'm having a lifetime issue when implementing an iterator on custom struct containing borrows of vecs. I've been trying different solutions but can't fix it by myself (I'm still a beginner) and I want ...
LucioleMaléfique's user avatar
2 votes
0 answers
169 views

I have encountered a certain behavior of the borrow checker that I find rather odd: if I have a &'a mut &'b mut T where 'b: 'a, T: 'b, it seems as though I should be able to treat it as just a ...
Anonymous's user avatar
  • 511
0 votes
0 answers
128 views

I have a struct (Lines) containing a vec of Coordinates. I'm trying to implement a non-consuming mutable iterator over non-overlapping sub-slices into this vector as &mut [Coordinate]. Each sub-...
Sjors Donkers's user avatar
2 votes
0 answers
111 views

To implement a two dimensional vector type, I tried to wrap std::vec::Vec inside my own struct and implement a two dimensional mutable iterator. I know, that this is not possible in safe Rust due to ...
kilian's user avatar
  • 79
0 votes
0 answers
88 views

I have a data structure called 'FluidSim' which is a bunch of cells. Think of a 2d grid (x,y) which then holds a vector of data for each cell (grid location). I want to make an iterator which lets me ...
SupaGu's user avatar
  • 621
2 votes
0 answers
65 views

I'm creating a custom data structure in Rust and trying to implement iterators for it. Following the example of the built-in collections (LinkedList, Vec, etc), I've created an IntoIter struct that ...
Brian's user avatar
  • 179
3 votes
0 answers
40 views

I am trying to implement an Iterator that will go through a matrix line by line. struct Matrix { col_count: usize, backing: Vec<bool> } fn get_row_mut<'a>(&'a mut self, row: ...
zshehov's user avatar
  • 31
1 vote
0 answers
37 views

I'm implementing Conway's Game of Life in various forms to reacquant myself with Rust. Currently I'm writing an implementation to use an iterator instead of nested for loops and got stuck on a ...
BlamKiwi's user avatar
  • 2,243

15 30 50 per page