Last active
December 17, 2015 07:18
-
-
Save smvv/5571416 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Env { | |
| out: ~str, | |
| } | |
| impl Env { | |
| fn write(&self, msg: ~str) { | |
| self.out += msg; | |
| } | |
| } | |
| fn callback(env: @Env) { | |
| env.write(~"hi"); | |
| } | |
| fn main() { | |
| let pattern = ~"a.*?"; | |
| let env = @Env {out: ~""}; | |
| callback(env); | |
| io::println(fmt!("%s -> %s", pattern, env.out)); | |
| } | |
| // test.rs:7:8: 7:16 error: assigning to immutable field | |
| // test.rs:7 self.out += msg; | |
| // ^~~~~~~~ | |
| // error: aborting due to previous error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Env { | |
| out: ~str, | |
| } | |
| impl Env { | |
| //fn write(&self, msg: ~str) { | |
| fn write(&mut self, msg: ~str) { | |
| self.out += msg; | |
| } | |
| } | |
| //fn callback(env: @Env) { | |
| fn callback(env: @mut Env) { | |
| env.write(~"hi"); | |
| } | |
| fn main() { | |
| let pattern = ~"a.*?"; | |
| //let env = @Env {out: ~""}; | |
| let env = @mut Env {out: ~""}; | |
| callback(env); | |
| //io::println(fmt!("%s -> %s", pattern, env.out)); | |
| io::println(fmt!("%s -> %s", pattern, copy env.out)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment