The problem is how variability is inherited through ownership. For something to change, its owner must be changeable. Property is inherited, with the exception of the new owner, while @ and & classified as owner. Thus, in this case, you have a dart to which the @Dart field @Dart , but not the content of the field, so mut on x does not mean that the content of the field is changed (indeed, it cannot be mutable, because otherwise it can change under kicking something else that applies to him).
A way around this is to either make the field a mutable field so that the owner of the dart structure changes, i.e. @mut Dart { .. } (it has a (small) runtime, and can lead to a program crash if it is mutated, borrowed as unchanged), or build it at a time. The former is not optimal, and the latter is difficult to achieve. However, the first may look like this:
struct Dart<T> { alpha: ~[@mut Dart<T>], embed: ~[@T], tagged: bool } // ... pub fn new_dart(&self, ) -> @mut Dart<T> { let dart = @mut Dart{alpha: ~[], embed: ~[], tagged: false}; dart.alpha = vec::from_elem(self.n + 1, dart); //dart.embed = vec::from_elem(self.n + 1, ); return dart; }
(What is required for the decision is not @mut "bind the node" , but it is not clear to me how to make it work in Rust.)
source share