You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was writing a generic function for parsing one floating point number in each line of a string. And when I write the following function, I need to add this where clause for the code to compile.
use num_traits::{Float,Num};use std::fmt::Debug;fnparse_vec<F:Float>(content:&str) -> Vec<F>where
<FasNum>::FromStrRadixErr:Debug,{
content
.lines().map(|float| F::from_str_radix(float,10).unwrap()).collect()}fnmain(){let s = "1.0\n2.0\n3.0";let v:Vec<f32> = parse_vec(s);assert_eq!(v, vec![1.0,2.0,3.0]);}
It's not really convenient because it propagates to all other generics I used. So, I think that enforcing FromStrRadixErr to implement debug by default is probably a good idea. But I may be wrong and there is maybe a good reason of not doing so.
The text was updated successfully, but these errors were encountered:
It would be a breaking change to require it now, unfortunately.
But there is also support/precedent from the standard library, e.g. FromStr::Err and TryFrom::Error have no requirements on those types.
The less-convenient fallback is that you can panic with a bespoke message about that float string, without including anything from the opaque FromStrRadixErr type.
I was writing a generic function for parsing one floating point number in each line of a string. And when I write the following function, I need to add this where clause for the code to compile.
It's not really convenient because it propagates to all other generics I used. So, I think that enforcing FromStrRadixErr to implement debug by default is probably a good idea. But I may be wrong and there is maybe a good reason of not doing so.
The text was updated successfully, but these errors were encountered: