Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- pub struct S {
- field: Option<u8>,
- }
- impl S {
- fn field(&mut self) -> &mut u8 {
- self.field.as_mut().expect("blop blop")
- }
- fn method(&mut self) {
- *self.field() = 1;
- *self.field() = 2;
- }
- }
- fn main() {
- let mut s = S { field: Some(0) };
- s.method();
- println!("{:?}", s);
- }
Add Comment
Please, Sign In to add comment