Skip to content

Commit

Permalink
Replace PathBuf with Path when ownership or mutability is not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Integral-Tech committed Dec 17, 2024
1 parent 574f1f3 commit 2885084
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn enumerate_devices() -> impl Iterator<Item = WriteTarget> {
let bsdname = OsStr::from_bytes(CStr::from_ptr(d.bsdname).to_bytes());
let mut rawdevname = OsString::from("r");
rawdevname.push(bsdname);
let devnode: PathBuf = PathBuf::from("/dev").join(rawdevname);
let devnode = Path::new("/dev").join(rawdevname);
let bsdname = bsdname.to_string_lossy().into();
free(d.bsdname as *mut c_void);

Expand Down Expand Up @@ -149,12 +149,12 @@ impl WriteTarget {
}
}

let devnode = PathBuf::from("/dev").join(name);
let devnode = Path::new("/dev").join(name);
if !devnode.exists() {
return Err(DeviceParseError::NotFound);
}

let sysnode = PathBuf::from("/sys/class/block").join(name);
let sysnode = Path::new("/sys/class/block").join(name);

let removable = match read_sys_file(sysnode.join("removable"))?
.as_ref()
Expand Down Expand Up @@ -195,10 +195,10 @@ impl WriteTarget {
})
}

fn from_normal_file(path: PathBuf) -> Result<Self, DeviceParseError> {
fn from_normal_file(path: &Path) -> Result<Self, DeviceParseError> {
Ok(WriteTarget {
name: path.to_string_lossy().into(),
devnode: path,
devnode: path.into(),
size: TargetSize(None),
model: Model(None),
removable: Removable::Unknown,
Expand Down Expand Up @@ -238,7 +238,7 @@ impl TryFrom<&Path> for WriteTarget {
}
}

Self::from_normal_file(value.to_owned())
Self::from_normal_file(value)
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/ui/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::File, path::PathBuf, sync::Arc};
use std::{fs::File, path::Path, sync::Arc};

use crate::{
logging::{init_logging_parent, LogPaths},
Expand Down Expand Up @@ -33,7 +33,7 @@ pub async fn main() {
};

debug!("Starting primary process");
match inner_main(state_dir, log_paths).await {
match inner_main(&state_dir, log_paths).await {
Ok(_) => (),
Err(e) => handle_toplevel_error(e),
}
Expand All @@ -52,7 +52,7 @@ fn handle_toplevel_error(err: anyhow::Error) {
}
}

async fn inner_main(state_dir: PathBuf, log_paths: LogPaths) -> anyhow::Result<()> {
async fn inner_main(state_dir: &Path, log_paths: LogPaths) -> anyhow::Result<()> {
let args = Args::parse();
let Command::Burn(args) = args.command;

Expand Down

0 comments on commit 2885084

Please sign in to comment.