Friends
I have a simple example using the num
crate that will not compile because:
13 | Err(err) => panic!(err),
| ^^^^^^^^^^^ `<T as num_traits::Num>::FromStrRadixErr` cannot be sent between threads safely
|
= help: the trait `std::marker::Send` is not implemented for `<T as num_traits::Num>::FromStrRadixErr`
Is this because of requirements of the num
crate that I cannot see?
The sample code is:
use num::Num;
struct Foo<T> {
v:T,
}
impl<T> Foo<T> {
fn new(v:&'static str) -> Foo<T>
where T: Num {
Foo{
v:match <T as Num>::from_str_radix(v, 10){
Ok(v) => v,
Err(err) => panic!(err),
},
}
}
}
fn main() {
let f:Foo<f64> = Foo::new("-1");
println!("Foo{{{}}}", f.v);
}
Changing the where
clause to:
where <T as Num>::FromStrRadixErr: 'static,
T: Num,
<T as Num>::FromStrRadixErr: std::marker::Send {
fixes it, but I do not understand why. I am unhappy with "magic incantations" so I would like to know! I need to kno the role of the life time 'static
in this context. The struct this is part of in the bigger code has a life time associated with it, surely that is the life time I should use. But why?
Also in the bigger case, but not here, I have to put std::fmt::Debug
into the where
clause for <T as Num>::FromStrRadixErr
. Why?