Skip to content

Instantly share code, notes, and snippets.

@Ronaldho80
Created November 30, 2016 13:42
Show Gist options
  • Save Ronaldho80/128986ab987ae2e58a6d307eac65f28e to your computer and use it in GitHub Desktop.
Save Ronaldho80/128986ab987ae2e58a6d307eac65f28e to your computer and use it in GitHub Desktop.
Question to the borrow checker
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