This code compiles fine:
use std::ops::Deref;
struct Data {
boxed: Box<&'static i32>
}
impl Data {
fn use_data(&self, user: impl for <'a> FnOnce(&'a i32)) {
user(*self.boxed)
}
}
However, modifying the definition of user
with this will cause the compilation to fail:
user: impl for <'a> FnOnce(<Box<&'a i32> as Deref>::Target)
// instead of for <'a> FnOnce(&'a i32)
This does not make sense to me as it is my understanding that <Box<T> as Deref>::Target
should be identical to T
. What am I missing in this example?