Last active
August 29, 2015 13:56
-
-
Save quux00/9242433 to your computer and use it in GitHub Desktop.
Reference functions in an impl
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 MyThing { | |
val: int | |
} | |
impl MyThing { | |
fn remove_first(s: &str) -> ~str { | |
s.slice_from(1).to_owned() | |
} | |
fn remove_last(&self, s: &str) -> ~str { | |
s.slice_to(s.len() - 1).to_owned() | |
} | |
} | |
fn main() { | |
let mt = MyThing{val: 42}; | |
let s1 = "abc"; | |
let r1 = mt.remove_last(s1); | |
println(r1); | |
let s2 = "123"; | |
let r2 = MyThing::remove_last("123"); error: first-class methods are not supported | |
println(r2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment