diff --git a/CHANGELOG.md b/CHANGELOG.md index db54a51a..8dbec6f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Changed +* Bump msrv to 1.75.0 #439 - @YJDoc2 +* Replace `derivative` with `derive_more` #439 - @YJDoc2 * Add build optimizations for release binary #434 - @pando85 * Minor cleanup and optimisations #435 - @cyqsimon diff --git a/Cargo.lock b/Cargo.lock index 0e25b6ee..bcffc9f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -169,7 +169,7 @@ dependencies = [ "clap_complete", "clap_mangen", "crossterm", - "derivative", + "derive_more", "http_req", "insta", "ipnetwork", @@ -550,10 +550,10 @@ dependencies = [ ] [[package]] -name = "derivative" -version = "2.2.0" +name = "derive-new" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535" dependencies = [ "proc-macro2", "quote", @@ -561,25 +561,35 @@ dependencies = [ ] [[package]] -name = "derive-new" -version = "0.5.9" +name = "derive_arbitrary" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3418329ca0ad70234b9735dc4ceed10af4df60eff9c8e7b06cb5e520d92c3535" +checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.79", ] [[package]] -name = "derive_arbitrary" -version = "1.3.2" +name = "derive_more" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" dependencies = [ "proc-macro2", "quote", "syn 2.0.79", + "unicode-xid", ] [[package]] @@ -2213,6 +2223,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "url" version = "2.5.2" diff --git a/Cargo.toml b/Cargo.toml index 51d53af8..bc8ec559 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ keywords = ["networking", "utilization", "cli"] license = "MIT" readme = "README.md" repository = "https://github.com/imsnif/bandwhich" -rust-version = "1.74.0" +rust-version = "1.75.0" description = "Display current network utilization by process, connection and remote IP/hostname" [features] @@ -32,7 +32,6 @@ chrono = "0.4" clap-verbosity-flag = "2.2.2" clap = { version = "4.5.19", features = ["derive"] } crossterm = "0.28.1" -derivative = "2.2.0" ipnetwork = "0.20.0" itertools = "0.13.0" log = "0.4.22" @@ -47,6 +46,7 @@ tokio = { version = "1.40", features = ["rt", "sync"] } trust-dns-resolver = "0.23.2" unicode-width = "0.2.0" strum = { version = "0.26.3", features = ["derive"] } +derive_more = {version = "1.0.0", features = ["debug"]} [target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] procfs = "0.17.0" @@ -71,7 +71,7 @@ clap = { version = "4.5.19", features = ["derive"] } clap-verbosity-flag = "2.2.2" clap_complete = "4.5.32" clap_mangen = "0.2.23" -derivative = "2.2.0" +derive_more = {version = "1.0.0", features = ["debug"]} strum = { version = "0.26.3", features = ["derive"] } [target.'cfg(target_os = "windows")'.build-dependencies] diff --git a/src/cli.rs b/src/cli.rs index 7a2fbc35..af21c6a9 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,11 +2,10 @@ use std::{net::Ipv4Addr, path::PathBuf}; use clap::{Args, Parser, ValueEnum, ValueHint}; use clap_verbosity_flag::{InfoLevel, Verbosity}; -use derivative::Derivative; +use derive_more::Debug; use strum::EnumIter; -#[derive(Clone, Debug, Derivative, Parser)] -#[derivative(Default)] +#[derive(Clone, Debug, Parser, Default)] #[command(name = "bandwhich", version)] pub struct Opt { #[arg(short, long)] @@ -34,7 +33,6 @@ pub struct Opt { pub log_to: Option, #[command(flatten)] - #[derivative(Default(value = "Verbosity::new(0, 0)"))] pub verbosity: Verbosity, #[command(flatten)] diff --git a/src/display/components/display_bandwidth.rs b/src/display/components/display_bandwidth.rs index a8fa1769..13049684 100644 --- a/src/display/components/display_bandwidth.rs +++ b/src/display/components/display_bandwidth.rs @@ -1,13 +1,15 @@ use std::fmt; -use derivative::Derivative; +use derive_more::Debug; use crate::cli::UnitFamily; -#[derive(Copy, Clone, Derivative)] -#[derivative(Debug)] +#[derive(Copy, Clone, Debug)] pub struct DisplayBandwidth { - #[derivative(Debug(format_with = "fmt_f64"))] + // Custom format for reduced precision. + // Workaround for FP calculation discrepancy between Unix and Windows. + // See https://github.com/rust-lang/rust/issues/111405#issuecomment-2055964223. + #[debug("{bandwidth:.10e}")] pub bandwidth: f64, pub unit_family: BandwidthUnitFamily, } @@ -19,17 +21,9 @@ impl fmt::Display for DisplayBandwidth { } } -/// Custom formatter with reduced precision. -/// -/// Workaround for FP calculation discrepancy between Unix and Windows. -/// See https://github.com/rust-lang/rust/issues/111405#issuecomment-2055964223. -fn fmt_f64(val: &f64, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { - write!(f, "{val:.10e}") -} - /// Type wrapper around [`UnitFamily`] to provide extra functionality. -#[derive(Copy, Clone, Derivative, Default, Eq, PartialEq)] -#[derivative(Debug = "transparent")] +#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)] +#[debug("{_0:?}")] pub struct BandwidthUnitFamily(UnitFamily); impl From for BandwidthUnitFamily { fn from(value: UnitFamily) -> Self { diff --git a/src/display/components/table.rs b/src/display/components/table.rs index dc1f68fe..4c66d3c4 100644 --- a/src/display/components/table.rs +++ b/src/display/components/table.rs @@ -1,6 +1,6 @@ -use std::{collections::HashMap, fmt, net::IpAddr, ops::Index, rc::Rc}; +use std::{collections::HashMap, net::IpAddr, ops::Index, rc::Rc}; -use derivative::Derivative; +use derive_more::Debug; use itertools::Itertools; use ratatui::{ layout::{Constraint, Rect}, @@ -165,8 +165,7 @@ impl TableData { /// /// Note that the number of columns here is independent of the number of columns /// being actually shown. If width-constrained, we might only show some of the columns. -#[derive(Clone, Derivative)] -#[derivative(Debug)] +#[derive(Clone, Debug)] struct NColsTableData { /// The name of each column. column_names: [&'static str; C], @@ -176,20 +175,13 @@ struct NColsTableData { /// /// This function should return a vector of column indices. /// The indices should be less than `C`; otherwise this will cause a runtime panic. - #[derivative(Debug(format_with = "debug_fn::"))] + #[debug("Rc")] column_selector: Rc, } /// Clippy wanted me to write this. 💢 type ColumnSelectorFn = dyn Fn(&DisplayLayout) -> Vec; -fn debug_fn( - _func: &Rc, - f: &mut fmt::Formatter, -) -> Result<(), fmt::Error> { - write!(f, "Rc") -} - /// A table displayed by bandwhich. #[derive(Clone, Debug)] pub struct Table {