我知道在 0.6 中删除了可变字段。我收到此代码的以下错误,
C:\Users\mflamer\Dropbox\Rust\Tests\gmap.rs:23:8: 23:18 错误:分配给不可变字段 C:\Users\mflamer\Dropbox\Rust\Tests\gmap.rs:23 dart。 alpha = vec::from_elem(self.n + 1, dart);
我在这里做错了什么?谢谢。
pub struct GMap<T> {
priv n: uint,
priv darts: ~[Dart<T>]
}
struct Dart<T> {
alpha: ~[@Dart<T>],
embed: ~[@T],
tagged: bool
}
impl<T> GMap<T> {
pub fn new(dim: uint) -> GMap<T> {
let mut map: GMap<T> = GMap{n: dim, darts: ~[]};
return map
}
pub fn new_dart(&self, ) -> @Dart<T> {
let mut dart = @Dart{alpha: ~[], embed: ~[], tagged: false};
dart.alpha = vec::from_elem(self.n + 1, dart);
//dart.embed = vec::from_elem(self.n + 1, );
return dart;
}
pub fn dim(&self) -> uint {
self.n
}
}
//pub fn traverse(&self,[bool,..])
enum Cell {
Null,
Vertex,
Edge,
Face,
Solid
}
fn main() {
let topo: GMap<Cell> = GMap::new(3);
}