2013-01-22 19:20:08 -06:00
|
|
|
struct SpeechMaker {
|
|
|
|
speeches: uint
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:47:41 -06:00
|
|
|
pub impl SpeechMaker {
|
2013-01-22 19:20:08 -06:00
|
|
|
fn talk(&mut self) {
|
|
|
|
self.speeches += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn give_a_few_speeches(speaker: &mut SpeechMaker) {
|
|
|
|
|
|
|
|
// Here speaker is reborrowed for each call, so we don't get errors
|
|
|
|
// about speaker being moved.
|
|
|
|
|
|
|
|
speaker.talk();
|
|
|
|
speaker.talk();
|
|
|
|
speaker.talk();
|
|
|
|
}
|
|
|
|
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2013-01-22 19:20:08 -06:00
|
|
|
let mut lincoln = SpeechMaker {speeches: 22};
|
|
|
|
give_a_few_speeches(&mut lincoln);
|
|
|
|
}
|