Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. #[derive(Debug)]
  2. pub struct S {
  3. field: Option<u8>,
  4. }
  5.  
  6. impl S {
  7. fn field(&mut self) -> &mut u8 {
  8. self.field.as_mut().expect("blop blop")
  9. }
  10.  
  11. fn method(&mut self) {
  12. *self.field() = 1;
  13. *self.field() = 2;
  14. }
  15. }
  16.  
  17. fn main() {
  18. let mut s = S { field: Some(0) };
  19. s.method();
  20. println!("{:?}", s);
  21. }
Add Comment
Please, Sign In to add comment