[pbs-devel] [PATCH proxmox 5/9] procfs: add variable bindings for std::fs::read
Maximiliano Sandoval
m.sandoval at proxmox.com
Tue Mar 4 15:40:47 CET 2025
These will produce an error in edition 2024 otherwise. The reason this
is needed is because the `unsafe` block has its own scope.
The bytes were defined inside of the let-mut block to preserve the
lifetime they had before this commit.
Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
proxmox-sys/src/linux/procfs/mod.rs | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/proxmox-sys/src/linux/procfs/mod.rs b/proxmox-sys/src/linux/procfs/mod.rs
index 3b25ce70..a1758bc0 100644
--- a/proxmox-sys/src/linux/procfs/mod.rs
+++ b/proxmox-sys/src/linux/procfs/mod.rs
@@ -228,9 +228,10 @@ static PROC_LAST_STAT: LazyLock<RwLock<(ProcFsStat, Instant, bool)>> =
pub fn read_proc_stat() -> Result<ProcFsStat, Error> {
let sample_time = Instant::now();
let update_duration;
- let mut stat =
- parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&std::fs::read("/proc/stat")?) })
- .unwrap();
+ let mut stat = {
+ let bytes = std::fs::read("/proc/stat")?;
+ parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&bytes) }).unwrap()
+ };
{
// read lock scope
@@ -755,7 +756,8 @@ pub struct Loadavg(pub f64, pub f64, pub f64);
impl Loadavg {
/// Read the load avage from `/proc/loadavg`.
pub fn read() -> Result<Self, Error> {
- Self::parse(unsafe { std::str::from_utf8_unchecked(&std::fs::read("/proc/loadavg")?) })
+ let bytes = std::fs::read("/proc/loadavg")?;
+ Self::parse(unsafe { std::str::from_utf8_unchecked(&bytes) })
}
/// Parse the value triplet.
--
2.39.5
More information about the pbs-devel
mailing list