Hello,
I have an error "cannot assign to immutable field". However, it is mutable as I
understand according to "inherited mutability" rule exposed in the tutorial
(section 'Structs'). The field in question is in a struct itself item of an
array, itself field in a super-structure (lol!) which is self. All this happens
in a method called on "&mut self". (And the compiler lets me change self
elsewhere in the same method.)
Thus, what is wrong? Or is it so that the mutability cascade is broken due to
the array? How then restore it and be able to change a struct item's field? I
guess arrays are mutable by default aren't they? (Or else, here it should due to
inherited mutability, since it is a field of a mutable struct.)
What do I miss?
[Code below untested yet due to error.]
fn expand (&mut self) {
// A mod table expands by doubling its list bucket capacity.
// Double array of lists, initially filled with NO_CELL values.
let NO_CELL : uint = -1 as uint; // flag for end-of-list
self.n_lists *= 2;
self.lists = vec::from_elem(self.n_lists, NO_CELL);
// replace cells into correct lists according to new key modulo.
let mut i_list : uint;
let mut i_cell : uint = 0;
for cell in self.cells.iter() {
// Link cell at start of correct list.
i_list = cell.key % self.n_lists;
cell.i_next = self.lists[i_list]; // ERROR ***
self.lists[i_list] = i_cell;
i_cell += 1;
}
}
I take the opportunity to ask whether there's an (i, item) iterator for arrays.
Thank you,
Denis
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev