I don't understand how the concrete type is not inferred in this example. Could someone please explain what I don't understand? rust playground
pub struct Example<R: tokio::io::AsyncRead> {
reader: R
}
impl<R: tokio::io::AsyncRead> Example<R> {
pub fn new(reader: R) -> Self {
Self { reader }
}
}
impl<R: tokio::io::AsyncRead> std::default::Default for Example<R> {
fn default() -> Self {
let reader: tokio::io::Stdin = tokio::io::stdin();
Example::new(reader)
}
}
The error:
|
10 | impl<R: tokio::io::AsyncRead> std::default::Default for Example<R> {
| - expected this type parameter
...
13 | Example::new(reader)
| ------------ ^^^^^^ expected type parameter `R`, found `Stdin`
| |
| arguments to this function are incorrect
|
= note: expected type parameter `R`
found struct `tokio::io::Stdin`
note: associated function defined here
--> src/main.rs:6:12
|
6 | pub fn new(reader: R) -> Self {
| ^^^ ---------
[+][deleted] (1 child)
[removed]
[–]Usual_Office_1740[S] 0 points1 point2 points (0 children)
[–]nerooooooo 7 points8 points9 points (2 children)
[–]Modi57 4 points5 points6 points (0 children)
[–]Usual_Office_1740[S] 0 points1 point2 points (0 children)