2014-05-30 02:03:06 +00:00
|
|
|
use std::collections::HashSet;
|
2013-02-09 06:21:45 +00:00
|
|
|
|
2012-10-22 06:02:02 +00:00
|
|
|
struct Foo {
|
2015-01-08 10:54:35 +00:00
|
|
|
n: HashSet<isize>,
|
2013-02-09 06:21:45 +00:00
|
|
|
}
|
|
|
|
|
2013-05-31 22:17:22 +00:00
|
|
|
impl Foo {
|
2015-01-08 10:54:35 +00:00
|
|
|
pub fn foo<F>(&mut self, mut fun: F) where F: FnMut(&isize) {
|
2015-01-31 17:20:46 +00:00
|
|
|
for f in &self.n {
|
2013-05-31 22:17:22 +00:00
|
|
|
fun(f);
|
|
|
|
}
|
2013-02-09 06:21:45 +00:00
|
|
|
}
|
2012-10-22 06:02:02 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 06:21:45 +00:00
|
|
|
fn bar(f: &mut Foo) {
|
2019-04-22 07:40:08 +00:00
|
|
|
f.foo(
|
|
|
|
//~^ ERROR cannot borrow `*f` as mutable
|
2014-02-10 12:44:03 +00:00
|
|
|
|a| { //~ ERROR closure requires unique access to `f`
|
|
|
|
f.n.insert(*a);
|
|
|
|
})
|
2012-10-22 06:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-04-03 13:28:36 +00:00
|
|
|
let mut f = Foo { n: HashSet::new() };
|
2013-02-09 06:21:45 +00:00
|
|
|
bar(&mut f);
|
2013-02-14 19:47:00 +00:00
|
|
|
}
|