Hi! Currently I write:
fn read<T>() -> T
where
T: FromStr,
<T as FromStr>::Err: Debug,
{
let mut buf = String::new();
stdin().read_line(&mut buf).unwrap();
buf.trim().parse::<T>().unwrap()
}
However, I would like to write:
trait Input = ???;
fn read<T: Input>() -> T
{
...;
}
Is that possible?
leudz
2
Hi, this is the best I can do, it's not really better than your code:
fn read<T: Input>() -> T
where T::Err: Debug {
// -- snip --
}
trait Input: FromStr where Self::Err: Debug {}
I believe this RFC and this one would allow:
fn read<T: Input>() -> T {
// -- snip --
}
trait Input: FromStr<Err: Debug> {}
1 Like
system
Closed
3
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.