Created
November 30, 2016 13:42
-
-
Save Ronaldho80/128986ab987ae2e58a6d307eac65f28e to your computer and use it in GitHub Desktop.
Question to the borrow checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct One<'a> { | |
foo: &'a f64, | |
bar: f64, | |
} | |
pub struct Two { | |
oof: f64, | |
rab: f64, | |
} | |
impl<'a> One<'a> { | |
pub fn inc(&'a mut self, x:f64) { | |
*self.foo += x; | |
} | |
pub fn dec(&'a mut self, x:f64) { | |
*self.foo -= x; | |
} | |
pub fn inc_dec(&'a mut self, x:f64) { | |
self.inc(x); | |
self.dec(x); | |
} | |
} | |
pub fn main() { | |
let mut one = One { | |
foo: &0.0, | |
bar: 0.0, | |
}; | |
one.inc(1.0); | |
one.dec(1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment