tools: add helpful vector and read operations

After importing the I/O ops trait via:
    use crate::tools::io::ops::*;

Instead of:
    let mut buffer = vec![0u8; 65536];
    file.read_exact(&mut buffer)?;
use:
    let buffer = file.read_exact_allocated(65536)?;

After importing the vector helpers via:
    use crate::tools::vec::{self, ops::*};

For a buffer which *could* be uninitialized but you prefer
zero-initialization anyway for security reasons, instead of:
    let mut buffer = vec![0u8; len];
use:
    let mut buffer = vec::undefined(len);
which zero-initializes, but, if the `valgrind` feature flag
is enabled, marks the vector as having undefined contents,
so reading from it will cause valgrind errors.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2019-05-22 14:43:24 +02:00
parent 8bea85b42e
commit 9cdda3f7c7
6 changed files with 721 additions and 0 deletions

View File

@ -47,6 +47,11 @@ pam = "0.7"
zstd = "0.4"
xdg = "2.2"
mio = "0.6"
valgrind_request = { version = "1.1", optional = true }
[features]
default = []
valgrind = ["valgrind_request"]
[replace]
"zstd-sys:1.4.8" = { path = "zstd-sys" }