Consider the following code:
pub fn use_r<I, R>(xs: I, r: &R) {
unimplemented!()
}
fn test<'a, R>(r: &'a mut R) {
let a = |r: &'a mut R| {
[(|| use_r(vec![0.].into_iter(), r))()]
};
a(r);
// a(r);
}
fn test2<R>(r: &mut R) {
let a = |r: &mut R| {
[(|| use_r(vec![0.].into_iter(), r))()]
};
a(r);
a(r);
}
test
compiles with the latest nightly
, but I cannot call a(r);
twice. test2
compiles with stable
and does what I want, but it does not compile on nightly
.
The motivation is that I have a RNG which I want to pass into an internal closure a few different times. What do I need to do to allow test2
to compile?