# Pre-RFC: Read::read\_into\_uninitialized

**URL:** <https://internals.rust-lang.org/t/pre-rfc-read-read-into-uninitialized/5241>\
**Category:** libs\
**Created:** [May 14, 2017, 5:50pm UTC](https://internals.rust-lang.org/t/pre-rfc-read-read-into-uninitialized/5241 "2017-05-14T17:50:41Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![comex](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/comex/32/2587_2.png) [@comex](https://internals.rust-lang.org/u/comex)\
**Post date:** [May 15, 2017, 1:20am UTC](https://internals.rust-lang.org/t/pre-rfc-read-read-into-uninitialized/5241/7 "2017-05-15T01:20:05Z")

</div>

It would be better to have an ‘uninitialized buffer’ trait rather than forcing every Read impl to take care of it (and use unsafe code). Something like

```rust
unsafe trait UninitializedBuffer<T> {
    fn get(&mut self) -> *mut [T];
    unsafe fn did_fill(&mut self, size: usize);
    // + safe helper methods to append, etc.
}
// example
unsafe impl<T> UninitializedBuffer<T> for Vec<T> {
    fn get(&mut self) -> *mut [T] {
        unsafe {
            slice::from_raw_parts_mut(self.as_mut_ptr().offset(self.len() as isize),
                                      self.capacity() - self.len()) as *mut [T]
        }
    }
    unsafe fn did_fill(&mut self, size: usize) {
        self.set_len(self.len() + size);
    }
}

```

---

_[View the full topic](https://internals.rust-lang.org/t/pre-rfc-read-read-into-uninitialized/5241)._
