diff --git a/src/daemon.rs b/src/daemon.rs index 6b1848d..4272486 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -26,7 +26,7 @@ use crate::{ use crate::{OwnedFdWithFlags, TokenFd}; -pub static UID: LazyLock = LazyLock::new(|| rustix::process::getuid()); +pub static UID: LazyLock = LazyLock::new(rustix::process::getuid); pub static USER_SOCKET_DIR: LazyLock<&'static Path> = LazyLock::new(|| { let dir: Box = env::var_os("XDG_RUNTIME_DIR") @@ -52,19 +52,23 @@ pub enum ConvenientAttrPath { } impl ConvenientAttrPath { + /// Not currently used, but here for completeness. + #[expect(dead_code)] pub fn clone_from_dotted(s: &str) -> Self { Self::Dotted(Box::from(s)) } + /// Not currently used, but here for completeness. + #[expect(dead_code)] pub fn clone_from_split(s: &[&str]) -> Self { - Self::from_str_iter(s.into_iter().map(Deref::deref)) + Self::from_str_iter(s.iter().map(Deref::deref)) } pub fn from_str_iter<'i, I>(iter: I) -> Self where I: Iterator, { - let boxed = iter.map(|s| Box::from(s)); + let boxed = iter.map(Box::from); Self::Split(Box::from_iter(boxed)) } @@ -254,10 +258,10 @@ impl Daemon { debug!("opened daemon to {:?} file descriptor {fd:?}", name); - let path = match &name { - Some(name) => Some(PathBuf::from(name).into_boxed_path()), - None => None, - }; + let path = name + .as_ref() + .map(PathBuf::from) + .map(PathBuf::into_boxed_path); Self { config_path, diff --git a/src/daemon_io.rs b/src/daemon_io.rs index 891a518..9b319b0 100644 --- a/src/daemon_io.rs +++ b/src/daemon_io.rs @@ -130,7 +130,7 @@ impl From for OwnedFdWithFlags { impl Read for &OwnedFdWithFlags { fn read(&mut self, buf: &mut [u8]) -> Result { - debug_assert!(buf.len() > 0); + debug_assert!(!buf.is_empty()); loop { buf.fill(0); match rustix::io::read(self.as_ref_owned(), &mut *buf) { diff --git a/src/daemon_tokfd.rs b/src/daemon_tokfd.rs index 05d5ec9..e00f5f2 100644 --- a/src/daemon_tokfd.rs +++ b/src/daemon_tokfd.rs @@ -52,7 +52,7 @@ impl FdInfo { match Self::guess_name(self.fd) { Ok(name) => { - let prev = self.name.set(Box::from(name)); + let prev = self.name.set(name); debug_assert_eq!(prev, Ok(())); }, Err(e) => { @@ -105,13 +105,14 @@ impl<'a> Display for FdInfoDisplay<'a> { } #[derive(Copy)] -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[non_exhaustive] pub enum FdKind { File, Socket, SockStream, Poller, + #[default] Unknown, } @@ -128,12 +129,6 @@ impl FdKind { } } -impl Default for FdKind { - fn default() -> FdKind { - FdKind::Unknown - } -} - #[derive(Copy)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TokenFd { diff --git a/src/main.rs b/src/main.rs index a54078e..e2c5214 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use tracing_subscriber::{EnvFilter, layer::SubscriberExt}; fn main_wrapped() -> Result<(), Box> { // Default RUST_LOG to warn if it's not specified. - if let None = env::var_os("RUST_LOG") { + if env::var_os("RUST_LOG").is_none() { unsafe { env::set_var("RUST_LOG", "warn"); } diff --git a/src/nixcmd.rs b/src/nixcmd.rs index 980d8a0..b5e2db5 100644 --- a/src/nixcmd.rs +++ b/src/nixcmd.rs @@ -5,27 +5,27 @@ #[allow(unused_imports)] use crate::prelude::*; -#[derive(Debug, Clone, PartialEq, Hash)] -pub(crate) struct NixEvalExpr { - pub(crate) expr: E, - pub(crate) attrpath: A, -} - -impl NixEvalExpr -where - E: AsRef, - A: AsRef, -{ - pub(crate) fn into_command(self) -> Command { - let mut cmd = Command::new("nix-instantiate"); - cmd.arg("--eval") - .arg("--json") - .arg("--strict") - .arg("--expr") - .arg(self.expr) - .arg("-A") - .arg(self.attrpath); - - cmd - } -} +//#[derive(Debug, Clone, PartialEq, Hash)] +//pub(crate) struct NixEvalExpr { +// pub(crate) expr: E, +// pub(crate) attrpath: A, +//} +// +//impl NixEvalExpr +//where +// E: AsRef, +// A: AsRef, +//{ +// pub(crate) fn into_command(self) -> Command { +// let mut cmd = Command::new("nix-instantiate"); +// cmd.arg("--eval") +// .arg("--json") +// .arg("--strict") +// .arg("--expr") +// .arg(self.expr) +// .arg("-A") +// .arg(self.attrpath); +// +// cmd +// } +//}