Created
September 18, 2012 02:03
-
-
Save erickt/3740847 to your computer and use it in GitHub Desktop.
This file contains 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
trait Serializer { | |
fn emit_uint(v: uint); | |
fn emit_rec(f: fn()); | |
fn emit_rec_field(f_name: &str, f_idx: uint, f: fn()); | |
} | |
trait Serializable { | |
fn serialize<S: Serializer>(s: S); | |
} | |
impl uint: Serializable { | |
fn serialize<S: Serializer>(s: S) { s.emit_uint(self) } | |
} | |
type t = { mut x: uint }; | |
impl t: Serializable { | |
fn serialize<S: Serializer>(s: S) { | |
do s.emit_rec || { | |
s.emit_rec_field("x", 0, || self.x.serialize(s)); | |
} | |
} | |
} | |
fn main() { } |
This file contains 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
foo3.rs:20:40: 20:46 error: illegal borrow unless pure: creating immutable alias to mutable field | |
foo3.rs:20 s.emit_rec_field("x", 0, || self.x.serialize(s)); | |
^~~~~~ | |
foo3.rs:20:40: 20:56 note: impure due to access to impure function | |
foo3.rs:20 s.emit_rec_field("x", 0, || self.x.serialize(s)); | |
^~~~~~~~~~~~~~~~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment