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

⚓ Rust    📅 2025-07-27    👤 surdeus    👁️ 12      

surdeus

Warning

This post was published 129 days ago. The information described in this article may have changed.

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?

2 posts - 2 participants

Read full topic

🏷️ Rust_feed