mirror of
https://git.proxmox.com/git/proxmox
synced 2025-07-27 04:45:48 +00:00
sys: add variable bindings for temporaries in unsafe blocks
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@proxmox.com>
This commit is contained in:
parent
e06277ac7a
commit
25c08ad247
@ -228,9 +228,10 @@ static PROC_LAST_STAT: LazyLock<RwLock<(ProcFsStat, Instant, bool)>> =
|
|||||||
pub fn read_proc_stat() -> Result<ProcFsStat, Error> {
|
pub fn read_proc_stat() -> Result<ProcFsStat, Error> {
|
||||||
let sample_time = Instant::now();
|
let sample_time = Instant::now();
|
||||||
let update_duration;
|
let update_duration;
|
||||||
let mut stat =
|
let mut stat = {
|
||||||
parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&std::fs::read("/proc/stat")?) })
|
let bytes = std::fs::read("/proc/stat")?;
|
||||||
.unwrap();
|
parse_proc_stat(unsafe { std::str::from_utf8_unchecked(&bytes) }).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
// read lock scope
|
// read lock scope
|
||||||
@ -755,7 +756,8 @@ pub struct Loadavg(pub f64, pub f64, pub f64);
|
|||||||
impl Loadavg {
|
impl Loadavg {
|
||||||
/// Read the load avage from `/proc/loadavg`.
|
/// Read the load avage from `/proc/loadavg`.
|
||||||
pub fn read() -> Result<Self, Error> {
|
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.
|
/// Parse the value triplet.
|
||||||
|
Loading…
Reference in New Issue
Block a user