I've been playing around with this snippet, and I'm stuck on this error:
error[E0759]: `self` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
--> src/lib.rs:36:27
|
33 | fn get_single_chunk<'a, T>(&'a self) -> Option<&'a T> {
| -------- this data with lifetime `'a`...
...
36 | for chunk in self.chunks() {
| ---- ^^^^^^
| |
| ...is captured here...
37 | if let Some(c) = (&chunk as &(dyn Any + 'static)).downcast_ref::<T>() {
| ------ ...and is required to live as long as `'static` here
I'm stuck on this. Yes, the reference it's is 'a
, but looking at Any::downcast_ref
, that reference seems okay. The trait requires that any captured lifetimes are 'static
(that is, trait Any: 'static {
, and that should be here, too, since it's a &dyn Chunk
and Chunk: Any
. So, I'm at a loss here, as to what ails the compiler. My best interpretation of this is that it wants &'static dyn Chunk
… which isn't what I want.
I've also tried it w/o the explicit cast:
error[E0599]: no method named `downcast_ref` found for reference `&dyn Chunk` in the current scope
--> src/cr3/mod.rs:81:36
|
81 | if let Some(c) = chunk.downcast_ref::<T>() {
| ^^^^^^^^^^^^ method not found in `&dyn Chunk`
Which also doesn't make sense to me, since Chunk: Any
, again.
Where am I going wrong?