Guest User

Untitled

a guest
Jan 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. #[derive(Debug)]
  2. struct Fubar {
  3. x: Option<i32>,
  4. y: i32
  5. }
  6.  
  7. impl Fubar {
  8. fn foo(&mut self) {
  9. for val in self.x {
  10. self.bar(val)
  11. }
  12. }
  13. fn bar(&mut self, n: i32) {
  14. self.y += n;
  15. }
  16. }
  17.  
  18. fn main() {
  19. let mut fubar = Fubar { x: Some(1), y: 0, };
  20. fubar.foo();
  21. println!("{:?}", fubar)
  22. }
Add Comment
Please, Sign In to add comment