Skip to content

Instantly share code, notes, and snippets.

@quux00
Last active August 29, 2015 13:56
Show Gist options
  • Save quux00/9242433 to your computer and use it in GitHub Desktop.
Save quux00/9242433 to your computer and use it in GitHub Desktop.
Reference functions in an impl
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