Rust 向量索引:无法移出取消引用

Rust 向量索引:无法移出取消引用,rust,Rust,我试图通过实现一些基本的数据结构来学习Rust。在这种情况下,矩阵 struct Matrix<T> { pub nrows: uint, pub ncols: uint, pub rows: Vec<T> } 但是我在标记的行中得到了这个错误: error: cannot move out of dereference (dereference is implicit, due to indexing) error: cannot assign to im

我试图通过实现一些基本的数据结构来学习Rust。在这种情况下,
矩阵

struct Matrix<T> {
  pub nrows: uint,
  pub ncols: uint,
  pub rows: Vec<T>
}
但是我在标记的行中得到了这个错误:

error: cannot move out of dereference (dereference is implicit, due to indexing)
error: cannot assign to immutable dereference (dereference is implicit, due to indexing)
因此,我要做的是使
trans_矩阵的
可变,并以某种方式修复解引用错误。我怎样才能解决这个问题?谢谢。

使用

*trans_matrix.rows.get_mut(j * i) = self.rows[i * j];

工作,但只是一个解决办法。我不知道需要多长时间,
IndexMut
才能像预期的那样工作,或者它是否已经工作了,但这是一段时间以前的首选方式。

信不信由你,我仍然有同样的错误:
error:无法移出去引用(由于索引的缘故,去引用是隐式的)*trans u matrix.rows.get_mut(j*I)=self.rows[I*j]。另外,
get_mut()
被标记为已弃用(使用索引)。@tolgap:使用我的设置进行编译,即使它抱怨死代码。请测试它。该代码不是为我编译的(相同错误)。我使用的是
rustc 0.12.0-nightly(c669411af)
rustc-v
rustc 0.12.0-nightly(2550243b4 2014-09-25 19:02:44+0000)
。另外,在我发布评论几秒钟后,我更改了上面评论中的链接,因为我在其中粘贴了错误的链接,假设您阅读评论的时间超过了这几秒钟。你绝对试着去编译gist,对吧?事实上,我是F5'ing,所以我抓到了上一个链接。你的编辑工作。我想原因是在我的
Matrix::new
函数中,我为
Matrix
结构创建了一个可变的
变量。当我改变这一点时,它起了作用!
*trans_matrix.rows.get_mut(j * i) = self.rows[i * j];