Skip to content

Commit

Permalink
Use and_then to make more elegant
Browse files Browse the repository at this point in the history
Co-authored-by: Guillaume Gomez <[email protected]>
  • Loading branch information
TigerLau1985 and GuillaumeGomez authored Sep 22, 2023
1 parent 35a2cf2 commit 5ac7b6a
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/c_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ pub extern "C" fn sysinfo_cpu_vendor_id(system: CSystem) -> RString {
let mut system: Box<System> = Box::from_raw(system as *mut System);
system.refresh_cpu();

let cpu = system.cpus().first().unwrap();
if let Ok(c) = CString::new(cpu.vendor_id()) {
Box::into_raw(system);
return c.into_raw() as _;
}
let c_string = if let Some(c) = system.cpus().first().and_then(|cpu| CString::new(cpu.vendor_id()).ok()) {
c.into_raw() as RString
} else {
std::ptr::null()
};
Box::into_raw(system);
std::ptr::null()
c_string
}
}

Expand Down

0 comments on commit 5ac7b6a

Please sign in to comment.