From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 05E331FF0E4 for ; Tue, 11 Aug 2026 17:03:24 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C4F5A21576; Tue, 11 Aug 2026 17:03:23 +0200 (CEST) From: Robert Obkircher To: pbs-devel@lists.proxmox.com Subject: [PATCH v1 proxmox 6/6] io: remove unused ByteVecExt trait with grow_ and resize_uninitialized Date: Tue, 11 Aug 2026 17:02:05 +0200 Message-ID: <20260811150237.527116-7-r.obkircher@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260811150237.527116-1-r.obkircher@proxmox.com> References: <20260811150237.527116-1-r.obkircher@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1786460582506 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.792 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: T4HK2UMZD75EAZ2WL2O7THMHGUPY3MD5 X-Message-ID-Hash: T4HK2UMZD75EAZ2WL2O7THMHGUPY3MD5 X-MailFrom: r.obkircher@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: These methods appear to be unused now, and in cases where dealing with uninitialized memory is necessary, it would be more appropriate to use safer methods like Vec::spare_capacity_mut. Signed-off-by: Robert Obkircher --- proxmox-io/src/vec/byte_vec.rs | 101 --------------------------------- proxmox-io/src/vec/mod.rs | 9 +-- 2 files changed, 1 insertion(+), 109 deletions(-) delete mode 100644 proxmox-io/src/vec/byte_vec.rs diff --git a/proxmox-io/src/vec/byte_vec.rs b/proxmox-io/src/vec/byte_vec.rs deleted file mode 100644 index 0a45ba0a..00000000 --- a/proxmox-io/src/vec/byte_vec.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! This module provides additional operations for `Vec`. -//! -//! Example: -//! ``` -//! # use std::io::Read; -//! use proxmox_io::vec::{self, ByteVecExt}; -//! -//! fn append_1024_to_vec(mut input: T, buffer: &mut Vec) -> std::io::Result<()> { -//! input.read_exact(unsafe { buffer.grow_uninitialized(1024) }) -//! } -//! ``` - -/// Some additional byte vector operations useful for I/O code. -/// Example: -/// ``` -/// # use std::io::Read; -/// # use proxmox_io::ReadExt; -/// use proxmox_io::vec::{self, ByteVecExt}; -/// -/// # fn code(mut file: std::fs::File, mut data: Vec) -> std::io::Result<()> { -/// file.read_exact(unsafe { -/// data.grow_uninitialized(1024) -/// })?; -/// # Ok(()) -/// # } -/// ``` -/// -/// [`ReadExt`]: crate::ReadExt -pub trait ByteVecExt { - /// Grow a vector without initializing its elements. The difference to simply using `reserve` - /// is that it also updates the actual length, making the newly allocated data part of the - /// slice. - /// - /// This is a shortcut for: - /// ```ignore - /// vec.reserve(more); - /// let total = vec.len() + more; - /// unsafe { - /// vec.set_len(total); - /// } - /// ``` - /// - /// This returns a mutable slice to the newly allocated space, so it can be used inline: - /// ``` - /// # use std::io::Read; - /// # use proxmox_io::vec::ByteVecExt; - /// # fn test(mut file: std::fs::File, buffer: &mut Vec) -> std::io::Result<()> { - /// file.read_exact(unsafe { buffer.grow_uninitialized(1024) })?; - /// # Ok(()) - /// # } - /// ``` - /// - /// # Safety - /// - /// When increasing the size, the new contents are uninitialized and have nothing to do with - /// the previously contained content. Since we cannot track this state through the type system, - /// this method is marked as an unsafe API for good measure. - /// - /// [`ReadExt`]: crate::ReadExt - unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8]; - - /// Resize a vector to a specific size without initializing its data. This is a shortcut for: - /// ```ignore - /// if new_size <= vec.len() { - /// vec.truncate(new_size); - /// } else { - /// unsafe { - /// vec.grow_uninitialized(new_size - vec.len()); - /// } - /// } - /// ``` - /// - /// # Safety - /// - /// When increasing the size, the new contents are uninitialized and have nothing to do with - /// the previously contained content. Since we cannot track this state through the type system, - /// this method is marked as an unsafe API for good measure. - unsafe fn resize_uninitialized(&mut self, total: usize); -} - -impl ByteVecExt for Vec { - unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8] { - let old_len = self.len(); - self.reserve(more); - let total = old_len + more; - unsafe { - self.set_len(total); - } - &mut self[old_len..] - } - - unsafe fn resize_uninitialized(&mut self, new_size: usize) { - if new_size <= self.len() { - self.truncate(new_size); - } else { - unsafe { - self.grow_uninitialized(new_size - self.len()); - } - } - } -} diff --git a/proxmox-io/src/vec/mod.rs b/proxmox-io/src/vec/mod.rs index e4cc9892..94f87735 100644 --- a/proxmox-io/src/vec/mod.rs +++ b/proxmox-io/src/vec/mod.rs @@ -17,7 +17,7 @@ //! //! Examples: //! ```no_run -//! use proxmox_io::vec::{self, ByteVecExt}; +//! use proxmox_io::vec; //! //! # let size = 64usize; //! # let more = 64usize; @@ -25,15 +25,8 @@ //! //! let mut buffer = unsafe { vec::uninitialized(size) }; // an actually uninitialized buffer //! vec::clear(&mut buffer); // zero out an &mut [u8] -//! -//! vec::clear(unsafe { -//! buffer.grow_uninitialized(more) // grow the buffer with uninitialized bytes -//! }); //! ``` -mod byte_vec; -pub use byte_vec::ByteVecExt; - /// Create an uninitialized byte vector of a specific size. /// /// This is just a shortcut for: -- 2.47.3