diff --git a/proxmox-tools/src/io/read.rs b/proxmox-tools/src/io/read.rs index a299205a..39d923a6 100644 --- a/proxmox-tools/src/io/read.rs +++ b/proxmox-tools/src/io/read.rs @@ -4,7 +4,7 @@ use std::io; use endian_trait::Endian; -use crate::vec::{self, ops::*}; +use crate::vec::{self, ByteVecExt}; /// Adds some additional related functionality for types implementing [`Read`](std::io::Read). /// diff --git a/proxmox-tools/src/vec.rs b/proxmox-tools/src/vec.rs index ef5565a9..7d0ed506 100644 --- a/proxmox-tools/src/vec.rs +++ b/proxmox-tools/src/vec.rs @@ -17,7 +17,7 @@ //! //! Examples: //! ```no_run -//! use proxmox::tools::vec::{self, ops::*}; +//! use proxmox::tools::vec::{self, ByteVecExt}; //! //! # let size = 64usize; //! # let more = 64usize; @@ -31,7 +31,9 @@ //! }); //! ``` -pub mod ops; +mod byte_vec; +pub use byte_vec::*; + /// Create an uninitialized byte vector of a specific size. /// diff --git a/proxmox-tools/src/vec/ops.rs b/proxmox-tools/src/vec/byte_vec.rs similarity index 85% rename from proxmox-tools/src/vec/ops.rs rename to proxmox-tools/src/vec/byte_vec.rs index 4813ef2c..ad98dcf9 100644 --- a/proxmox-tools/src/vec/ops.rs +++ b/proxmox-tools/src/vec/byte_vec.rs @@ -3,7 +3,7 @@ //! Example: //! ``` //! # use std::io::Read; -//! use proxmox::tools::vec::{self, ops::*}; +//! use proxmox::tools::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) }) @@ -14,8 +14,8 @@ /// Example: /// ``` /// # use std::io::Read; -/// # use proxmox::tools::io::{self, ops::*}; -/// use proxmox::tools::vec::{self, ops::*}; +/// # use proxmox::tools::io::{self, ReadExt}; +/// use proxmox::tools::vec::{self, ByteVecExt}; /// /// # fn code(mut file: std::fs::File, mut data: Vec) -> std::io::Result<()> { /// file.read_exact(unsafe { @@ -26,14 +26,14 @@ /// ``` /// /// Note that this module also provides a safe alternative for the case where -/// `grow_uninitialized()` is directly followed by a `read_exact()` call via the [`ReadExtOps`] +/// `grow_uninitialized()` is directly followed by a `read_exact()` call via the [`ReadExt`] /// trait: /// ```ignore /// file.append_to_vec(&mut data, 1024)?; /// ``` /// -/// [`ReadExtOps`]: crate::io::ops::ReadExtOps -pub trait VecU8ExtOps { +/// [`ReadExt`]: crate::io::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. @@ -50,7 +50,7 @@ pub trait VecU8ExtOps { /// This returns a mutable slice to the newly allocated space, so it can be used inline: /// ``` /// # use std::io::Read; - /// # use proxmox::tools::vec::ops::*; + /// # use proxmox::tools::vec::ByteVecExt; /// # fn test(mut file: std::fs::File, buffer: &mut Vec) -> std::io::Result<()> { /// file.read_exact(unsafe { buffer.grow_uninitialized(1024) })?; /// # Ok(()) @@ -58,13 +58,13 @@ pub trait VecU8ExtOps { /// ``` /// /// Although for the above case it is recommended to use the even shorter version from the - /// [`ReadExtOps`] trait: + /// [`ReadExt`] trait: /// ```ignore - /// // use crate::tools::vec::ops::ReadExtOps; + /// // use crate::tools::vec::ByteVecExt; /// file.append_to_vec(&mut buffer, 1024)?; /// ``` /// - /// [`ReadExtOps`]: crate::io::ops::ReadExtOps + /// [`ReadExt`]: crate::io::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: @@ -80,7 +80,7 @@ pub trait VecU8ExtOps { unsafe fn resize_uninitialized(&mut self, total: usize); } -impl VecU8ExtOps for Vec { +impl ByteVecExt for Vec { unsafe fn grow_uninitialized(&mut self, more: usize) -> &mut [u8] { let old_len = self.len(); self.reserve(more);