Why BufReader/BufWriter implement for `?Sized` generics?

I came across something in the std::io API that I don't quite understand. Namely, BufReader/BufWriter are implemented for ?Sized generic types, but there seems to be no way in which to use them with types that are !Sized. Namely, using BufReader as our focus, the docs state:

pub struct BufReader<R: ?Sized> { /* private fields */ }

and there is

impl<R: Read> BufReader<R> {
    pub fn new(inner: R) -> BufReader<R>;
}

but, from what I can see, there is no way to construct BufReader with an unsized generic type. Is there some inernal use case for this?

You can unsize coerce after the BufReader is created.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.