【发布时间】:2014-09-28 13:19:52
【问题描述】:
我正在尝试通过实现一些基本数据结构来学习 Rust。在这种情况下,Matrix。
struct Matrix<T> {
pub nrows: uint,
pub ncols: uint,
pub rows: Vec<T>
}
现在,我想用这个函数转置Matrix:
pub fn transpose(&self) -> Matrix<T> {
let mut trans_matrix = Matrix::new(self.ncols, self.nrows);
for i in range(0u, self.nrows - 1u) {
for j in range(0u, self.ncols - 1u) {
trans_matrix.rows[j*i] = self.rows[i*j]; // error
}
}
trans_matrix
}
但我在标记线上收到此错误:
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_matrix 的rows 可变,并以某种方式修复取消引用错误。我该如何解决这个问题?谢谢。
【问题讨论】:
标签: rust