Skip to content

Instantly share code, notes, and snippets.

@Gankra
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gankra/481ca253d89cfea60dbe to your computer and use it in GitHub Desktop.
Save Gankra/481ca253d89cfea60dbe to your computer and use it in GitHub Desktop.
Simple Compilable Rust Example
struct SomeStruct{
data: uint
}
impl SomeStruct{
fn setData (&mut self, value: uint) {
self.data = value
}
fn getData (&self) -> uint {
self.data
}
fn incrementData (&mut self) {
self.setData(self.getData() + 1);
}
}
fn main () {
let mut foo = SomeStruct{data: 0};
println!("{}", foo.getData());
foo.incrementData();
foo.incrementData();
println!("{}", foo.getData());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment