From 9110a69bd83118bdf0a2609f7788f5946c3909f7 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 1 Jul 2019 10:39:41 +0200 Subject: [PATCH] tools: remove read/write now completely replaced by proxmox::tools::io::{ReadExt, WriteExt} Signed-off-by: Wolfgang Bumiller --- src/tools.rs | 2 -- src/tools/read.rs | 50 ---------------------------------------------- src/tools/write.rs | 43 --------------------------------------- 3 files changed, 95 deletions(-) delete mode 100644 src/tools/read.rs delete mode 100644 src/tools/write.rs diff --git a/src/tools.rs b/src/tools.rs index 011ca19c..74885d35 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -34,8 +34,6 @@ pub mod tty; pub mod signalfd; pub mod daemon; pub mod procfs; -pub mod read; -pub mod write; pub mod acl; pub mod xattr; pub mod vec; diff --git a/src/tools/read.rs b/src/tools/read.rs deleted file mode 100644 index 0c64699f..00000000 --- a/src/tools/read.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! Utility traits for types which implement `std::io::Read` to quickly read primitively typed -//! values such as binary integers from a stream. - -use std::io; -use std::mem; - -use endian_trait::Endian; - -pub trait ReadUtilOps { - /// Read a value of type `T`. - /// Note that it *should* be `repr(C, packed)` or similar. - fn read_value(&mut self) -> io::Result; - - /// Read a big-endian value of type `T`. - /// Note that it *should* be `repr(C, packed)` or similar. - fn read_value_be(&mut self) -> io::Result { - Ok(self.read_value::()?.from_be()) - } - - /// Read a little-endian value of type `T`. - /// Note that it *should* be `repr(C, packed)` or similar. - fn read_value_le(&mut self) -> io::Result { - Ok(self.read_value::()?.from_le()) - } - - /// Read an exact number of bytes into a newly allocated vector. - fn read_exact_allocated(&mut self, size: usize) -> io::Result>; -} - -impl ReadUtilOps for R { - fn read_value(&mut self) -> io::Result { - let mut data: T = unsafe { mem::uninitialized() }; - self.read_exact(unsafe { - std::slice::from_raw_parts_mut( - &mut data as *mut T as *mut u8, - mem::size_of::(), - ) - })?; - Ok(data) - } - - fn read_exact_allocated(&mut self, size: usize) -> io::Result> { - let mut out = Vec::with_capacity(size); - unsafe { - out.set_len(size); - } - self.read_exact(&mut out)?; - Ok(out) - } -} diff --git a/src/tools/write.rs b/src/tools/write.rs deleted file mode 100644 index 1bb4cf57..00000000 --- a/src/tools/write.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! Utility traits for types which implement `std::io::Write` to easily write primitively typed -//! values such as binary integers to a stream. - -use std::io; -use std::mem; - -use endian_trait::Endian; - -pub trait WriteUtilOps { - /// Write a value of type `T`. - /// Note that it *should* be `repr(C, packed)` or similar. - fn write_value(&mut self, value: &T) -> io::Result; - - /// Write a big-endian value of type `T`. - /// Note that it *should* be `repr(C, packed)` or similar. - fn write_value_be(&mut self, value: T) -> io::Result { - self.write_value(&value.to_be()) - } - - /// Write a little-endian value of type `T`. - /// Note that it *should* be `repr(C, packed)` or similar. - fn write_value_le(&mut self, value: T) -> io::Result { - self.write_value(&value.to_le()) - } - - /// Convenience `write_all()` alternative returning the length instead of `()`. - fn write_all_len(&mut self, value: &[u8]) -> io::Result; -} - -impl WriteUtilOps for R { - fn write_value(&mut self, value: &T) -> io::Result { - let size = mem::size_of::(); - self.write_all(unsafe { - std::slice::from_raw_parts(value as *const T as *const u8, size) - })?; - Ok(size) - } - - fn write_all_len(&mut self, value: &[u8]) -> io::Result { - self.write_all(value)?; - Ok(value.len()) - } -}