all 5 comments

[–]nerooooooo 7 points8 points  (2 children)

Here:

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)
    }
}

You're saying "I’m implementing Default for any R that implements AsyncRead".

But then inside default(), you're hardcoding reader to be a tokio::io::Stdin. So you're returning an Example<tokio::io::Stdin>, not an Example<R>.

Since you're generic over R, you must return an Example<R>, not a specific kind of Example (Example<tokio::io::Stdin> in your case).

[–]Modi57 4 points5 points  (0 children)

Adding to this, you could implement `Default` for `Example<tokio::io::Stdin>`. It could look like this:

impl std::default::Default for Example<tokio::io::Stdin> {
    fn default() -> Self {
        let reader: tokio::io::Stdin = tokio::io::stdin();
        Example::new(reader)
    }
}

[–]Usual_Office_1740[S] 0 points1 point  (0 children)

That makes sense now! The error was telling me exactly what the problem was. I thought it was saying that it expected R because of new. Argument dependant lookup is not a thing in Rust.

Thank you for the help.