We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
VecDeque::read_to_string
1 parent b015b32 commit 3089f51Copy full SHA for 3089f51
std/src/io/impls.rs
@@ -474,15 +474,8 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
474
475
#[inline]
476
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
477
- // We have to use a single contiguous slice because the `VecDequeue` might be split in the
478
- // middle of an UTF-8 character.
479
- let len = self.len();
480
- let content = self.make_contiguous();
481
- let string = str::from_utf8(content).map_err(|_| io::Error::INVALID_UTF8)?;
482
- buf.try_reserve(len)?;
483
- buf.push_str(string);
484
- self.clear();
485
- Ok(len)
+ // SAFETY: We only append to the buffer
+ unsafe { io::append_to_string(buf, |buf| self.read_to_end(buf)) }
486
}
487
488
0 commit comments