I have a case where I need a thread local variable for each of a set of (floating point type, unsigned integer type). Currently, for f64 and u32, I call it THIS_THREAD_TAPE_F64_U32.
I cannot figure out how to write a generic function, e.g. my_fun<F, U>, that can access the tape corresponding to the floating point type F and the unsigned integer type U ?
Compiling cargo_test v0.1.0 (/Users/bradbell/trash/rust/cargo_test)
error[E0597]: `localkey` does not live long enough
--> src/main.rs:36:4
|
35 | let localkey : LocalKey< RefCell< Tape<f64, u32> > > = get_this_thr...
| -------- binding `localkey` declared here
36 | localkey.with_borrow( |tape| {
| -^^^^^^^
| |
| ____borrowed value does not live long enough
| |
37 | | print!( "tape.value = {}", tape.value.len());
38 | | print!( "tape.index = {}", tape.index.len());
39 | | } );
| |______- argument requires that `localkey` is borrowed for `'static`
40 | }
| - `localkey` dropped here while still borrowed
For more information about this error, try `rustc --explain E0597`.
No, that's the reason for the change, as I understand it. To be more clear (mentions dyn) and not refer to safety. It means that the trait can't be implemented for dyn T, since the Self type has to be Sized. A dyn T type gets an automatic implementation of its own trait, but that's not possible in this case. If you only need Sized for certain methods, you can add where Self: Sized to just them instead.