From 4f9fe856a25ab29345b90e7725509e9ee38a37be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:41 +0200 Subject: Adding upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- library/std/src/net/display_buffer.rs | 40 ----------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 library/std/src/net/display_buffer.rs (limited to 'library/std/src/net/display_buffer.rs') diff --git a/library/std/src/net/display_buffer.rs b/library/std/src/net/display_buffer.rs deleted file mode 100644 index 7aadf06e9..000000000 --- a/library/std/src/net/display_buffer.rs +++ /dev/null @@ -1,40 +0,0 @@ -use crate::fmt; -use crate::mem::MaybeUninit; -use crate::str; - -/// Used for slow path in `Display` implementations when alignment is required. -pub struct DisplayBuffer { - buf: [MaybeUninit; SIZE], - len: usize, -} - -impl DisplayBuffer { - #[inline] - pub const fn new() -> Self { - Self { buf: MaybeUninit::uninit_array(), len: 0 } - } - - #[inline] - pub fn as_str(&self) -> &str { - // SAFETY: `buf` is only written to by the `fmt::Write::write_str` implementation - // which writes a valid UTF-8 string to `buf` and correctly sets `len`. - unsafe { - let s = MaybeUninit::slice_assume_init_ref(&self.buf[..self.len]); - str::from_utf8_unchecked(s) - } - } -} - -impl fmt::Write for DisplayBuffer { - fn write_str(&mut self, s: &str) -> fmt::Result { - let bytes = s.as_bytes(); - - if let Some(buf) = self.buf.get_mut(self.len..(self.len + bytes.len())) { - MaybeUninit::write_slice(buf, bytes); - self.len += bytes.len(); - Ok(()) - } else { - Err(fmt::Error) - } - } -} -- cgit v1.2.3