diff --git a/proxmox-tools/src/io.rs b/proxmox-tools/src/io.rs index 878b5b5a..9e9d9e44 100644 --- a/proxmox-tools/src/io.rs +++ b/proxmox-tools/src/io.rs @@ -1,10 +1,12 @@ //! Module providing I/O helpers (sync and async). //! -//! The [`ops`](io::ops) module provides helper traits for types implementing [`Read`](std::io::Read). -//! -//! The top level functions in of this module here are used for standalone implementations of -//! various functionality which is actually intended to be available as methods to types -//! implementing `AsyncRead`, which, however, without async/await cannot be methods due to them -//! having non-static lifetimes in that case. +//! The [`ReadExt`] trait provides additional operations for handling byte buffers for types +//! implementing [`Read`](std::io::Read). -pub mod ops; +// DEPRECATED: +pub mod ops { + pub use super::ReadExt as ReadExtOps; +} + +mod read; +pub use read::*; diff --git a/proxmox-tools/src/io/ops.rs b/proxmox-tools/src/io/read.rs similarity index 93% rename from proxmox-tools/src/io/ops.rs rename to proxmox-tools/src/io/read.rs index 5fb33cef..a299205a 100644 --- a/proxmox-tools/src/io/ops.rs +++ b/proxmox-tools/src/io/read.rs @@ -1,7 +1,4 @@ -//! This module provides additional operations for handling byte buffers for types implementing -//! [`Read`](std::io::Read). -//! -//! See the [`ReadExtOps`](ops::ReadExtOps) trait for examples. +//! Helpers for `Read`. use std::io; @@ -16,7 +13,7 @@ use crate::vec::{self, ops::*}; /// /// Examples: /// ```no_run -/// use proxmox::tools::io::ops::*; +/// use proxmox::tools::io::ReadExt; /// /// # fn code() -> std::io::Result<()> { /// let mut file = std::fs::File::open("some.data")?; @@ -35,7 +32,7 @@ use crate::vec::{self, ops::*}; /// /// ```no_run /// # use endian_trait::Endian; -/// # use proxmox::tools::io::ops::*; +/// # use proxmox::tools::io::ReadExt; /// /// #[derive(Endian)] /// #[repr(C)] @@ -53,7 +50,7 @@ use crate::vec::{self, ops::*}; /// ``` /// /// [`Endian`]: https://docs.rs/endian_trait/0.6/endian_trait/trait.Endian.html -pub trait ReadExtOps { +pub trait ReadExt { /// Read data into a newly allocated vector. This is a shortcut for: /// ```ignore /// let mut data = Vec::with_capacity(len); @@ -65,7 +62,7 @@ pub trait ReadExtOps { /// /// With this trait, we just use: /// ```no_run - /// use proxmox::tools::io::ops::*; + /// use proxmox::tools::io::ReadExt; /// # fn code(mut reader: std::fs::File, len: usize) -> std::io::Result<()> { /// let data = reader.read_exact_allocated(len)?; /// # Ok(()) @@ -89,7 +86,7 @@ pub trait ReadExtOps { /// /// ```no_run /// # use endian_trait::Endian; - /// use proxmox::tools::io::ops::*; + /// use proxmox::tools::io::ReadExt; /// /// #[derive(Endian)] /// #[repr(C, packed)] @@ -121,7 +118,7 @@ pub trait ReadExtOps { /// /// ```no_run /// # use endian_trait::Endian; - /// use proxmox::tools::io::ops::*; + /// use proxmox::tools::io::ReadExt; /// /// #[derive(Endian)] /// #[repr(C, packed)] @@ -153,7 +150,7 @@ pub trait ReadExtOps { /// /// ```no_run /// # use endian_trait::Endian; - /// use proxmox::tools::io::ops::*; + /// use proxmox::tools::io::ReadExt; /// /// #[derive(Endian)] /// #[repr(C, packed)] @@ -175,7 +172,7 @@ pub trait ReadExtOps { unsafe fn read_be_value(&mut self) -> io::Result; } -impl ReadExtOps for R { +impl ReadExt for R { fn read_exact_allocated(&mut self, size: usize) -> io::Result> { let mut out = unsafe { vec::uninitialized(size) }; self.read_exact(&mut out)?;