Skip to content

Instantly share code, notes, and snippets.

@Kimundi
Created February 17, 2014 11:26
Show Gist options
  • Save Kimundi/9048927 to your computer and use it in GitHub Desktop.
Save Kimundi/9048927 to your computer and use it in GitHub Desktop.
pub struct Property<T> {
priv val: T
}
impl<T> Property<T> {
fn new(new_val: T) -> Property<T> {
Property {
val: new_val
}
}
fn get<'a>(&'a self) -> &'a T {
&self.val
}
fn get_mut<'a>(&'a mut self) -> &'a mut T {
&mut self.val
}
fn set(&mut self, new_val: T) {
self.val = new_val
}
}
fn main() {
let mut prop = Property::new(42);
println!("{:?}", prop.get())
prop.set(256);
println!("{:?}", prop.get())
*prop.get_mut() *= 4;
println!("{:?}", prop.get())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment