From b48209a33accaa9a8766b6dc77782a6f9f997c63 Mon Sep 17 00:00:00 2001 From: Qyriad Date: Tue, 10 Mar 2026 18:46:55 +0100 Subject: [PATCH] fix a bunch of warnings! --- src/args.rs | 62 --------------------------------------------------- src/color.rs | 11 ++++----- src/lib.rs | 13 ++++------- src/line.rs | 3 --- src/main.rs | 1 - src/source.rs | 4 ++-- 6 files changed, 10 insertions(+), 84 deletions(-) diff --git a/src/args.rs b/src/args.rs index 5a0bda7..8c528a2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -11,50 +11,6 @@ use clap::ColorChoice; use crate::prelude::*; -//#[derive(Debug, Clone, PartialEq)] -//#[derive(clap::Args)] -//#[group(required = true, multiple = false)] -//pub enum Config -//{ -// Flake, -//} - -#[derive(Debug, Clone, PartialEq)] -pub struct NixOsOption { - name: String, - value: String, -} - -#[derive(Debug, Clone, PartialEq)] -pub struct NixOptionParseError(pub Box); - -impl Display for NixOptionParseError { - fn fmt(&self, f: &mut Formatter) -> FmtResult { - write!(f, "{}", self.0) - } -} - -impl From for NixOptionParseError { - fn from(value: String) -> Self { - Self(value.into_boxed_str()) - } -} - -impl StdError for NixOptionParseError {} - -impl FromStr for NixOsOption { - type Err = NixOptionParseError; - - fn from_str(s: &str) -> Result { - // FIXME: allow escaping equals sign? - let Some(delim) = s.find('=') else { - return Err(format!("equals sign not found in {}", s).into()); - }; - - todo!(); - } -} - #[derive(Debug, Clone, PartialEq, clap::Parser)] pub struct AppendCmd { #[arg(required = true)] @@ -64,15 +20,10 @@ pub struct AppendCmd { pub value: Arc, } -#[derive(Debug, Clone, PartialEq, clap::Parser)] -pub struct DeltaCmd {} - #[derive(Debug, Clone, PartialEq, clap::Subcommand)] #[command(flatten_help = true)] pub enum Subcommand { Append(AppendCmd), - // TODO: rename - Delta(DeltaCmd), } static DEFAULT_PATH: LazyLock> = LazyLock::new(|| { @@ -114,16 +65,3 @@ pub struct Args { #[command(subcommand)] pub subcommand: Subcommand, } -///// Flakeref to a base configuration to modify. -//#[arg(group = "config", long, default_value("."))] -//#[arg(long, default_value(Some(".")))] -//flake: Option>>, -// -//#[arg(group = "config", long)] -//expr: Option, - -//impl Parser { -// fn eval_cmd(&self) { -// todo!(); -// } -//} diff --git a/src/color.rs b/src/color.rs index 9c6591c..f51dc77 100644 --- a/src/color.rs +++ b/src/color.rs @@ -2,6 +2,9 @@ // // SPDX-License-Identifier: EUPL-1.1 +// The entire point of this module. +#![allow(clippy::declare_interior_mutable_const)] + use std::{ env, sync::{LazyLock, OnceLock}, @@ -22,13 +25,7 @@ fn is_color_reqd() -> bool { fn is_clicolor_forced() -> bool { env::var("CLICOLOR_FORCE") - .map(|value| { - if value.is_empty() || value == "0" { - false - } else { - true - } - }) + .map(|value| !(value.is_empty() || value == "0")) .unwrap_or(false) } diff --git a/src/lib.rs b/src/lib.rs index e82f63d..58d98a1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ pub(crate) mod prelude { use prelude::*; pub mod args; -pub use args::{AppendCmd, Args, DeltaCmd}; +pub use args::{AppendCmd, Args}; mod color; pub use color::{_CLI_ENABLE_COLOR, SHOULD_COLOR}; pub mod line; @@ -80,11 +80,6 @@ static MK_OVERRIDE_RE: LazyLock = LazyLock::new(|| { Regex::new(r"(?-u)\bmkOverride\s+\((?[\d-]+)\)").unwrap() }); -#[tracing::instrument(level = "debug")] -pub fn do_delta(args: Arc, delta_args: DeltaCmd) -> Result<(), BoxDynError> { - todo!(); -} - #[tracing::instrument(level = "debug")] pub fn do_append(args: Arc, append_args: AppendCmd) -> Result<(), BoxDynError> { let filepath = Path::new(&args.file); @@ -109,9 +104,9 @@ pub fn do_append(args: Arc, append_args: AppendCmd) -> Result<(), BoxDynEr let new_pri_line = get_next_prio_line( source_file.clone(), - append_args.name.into(), + append_args.name, new_pri, - append_args.value.into(), + append_args.value, )?; debug!("new_pri_line={new_pri_line}"); @@ -154,7 +149,7 @@ fn maybe_extract_prio_from_line(line: &SourceLine) -> Option { pub fn get_where(dynamic_nix: SourceFile) -> Result { let lines = dynamic_nix.lines()?; let prio = lines - .into_iter() + .iter() .filter_map(maybe_extract_prio_from_line) .sorted_unstable() .next() // Priorities with lower integer values are "stronger" priorities. diff --git a/src/line.rs b/src/line.rs index c1470c9..aa0d706 100644 --- a/src/line.rs +++ b/src/line.rs @@ -7,7 +7,6 @@ use std::num::NonZeroU64; #[allow(unused_imports)] use crate::prelude::*; - #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Line(pub u64); @@ -43,5 +42,3 @@ impl Line { self.0 + 1 } } - -pub struct Lines(Vec); diff --git a/src/main.rs b/src/main.rs index 196b904..c45a56a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,6 @@ fn main_wrapped() -> Result<(), Box> { use dynix::args::Subcommand::*; match &args.subcommand { Append(append_args) => dynix::do_append(args.clone(), append_args.clone())?, - Delta(delta_args) => dynix::do_delta(args.clone(), delta_args.clone())?, }; } diff --git a/src/source.rs b/src/source.rs index ae90189..287f72e 100644 --- a/src/source.rs +++ b/src/source.rs @@ -40,7 +40,7 @@ pub fn replace_file<'a>( drop(writer); // Rename the temporary file to the new file, which is atomic (TODO: I think). - fs_err::rename(&tmp_path, &path)?; + fs_err::rename(&tmp_path, path)?; Ok(()) } @@ -62,7 +62,7 @@ impl SourceLine { } pub fn text_bytes(&self) -> Arc<[u8]> { - let len: usize = self.text.as_bytes().len(); + let len: usize = self.text.len(); // We need to consume an Arc, but we are &self. let text = Arc::clone(&self.text);