Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace derivative crate with derive_more crate #439

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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]
Expand Down
6 changes: 2 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -34,7 +33,6 @@ pub struct Opt {
pub log_to: Option<PathBuf>,

#[command(flatten)]
#[derivative(Default(value = "Verbosity::new(0, 0)"))]
pub verbosity: Verbosity<InfoLevel>,

#[command(flatten)]
Expand Down
26 changes: 9 additions & 17 deletions src/display/components/display_bandwidth.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::fmt;

use derivative::Derivative;

use crate::cli::UnitFamily;
use derive_more::Debug;
use std::fmt;

#[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,
}
Expand All @@ -19,17 +19,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<UnitFamily> for BandwidthUnitFamily {
fn from(value: UnitFamily) -> Self {
Expand Down
16 changes: 4 additions & 12 deletions src/display/components/table.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -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<const C: usize> {
/// The name of each column.
column_names: [&'static str; C],
Expand All @@ -176,20 +175,13 @@ struct NColsTableData<const C: usize> {
///
/// 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::<C>"))]
#[debug("Rc</* function pointer */>")]
column_selector: Rc<ColumnSelectorFn>,
}

/// Clippy wanted me to write this. 💢
type ColumnSelectorFn = dyn Fn(&DisplayLayout) -> Vec<usize>;

fn debug_fn<const C: usize>(
_func: &Rc<ColumnSelectorFn>,
f: &mut fmt::Formatter,
) -> Result<(), fmt::Error> {
write!(f, "Rc</* function pointer */>")
}

/// A table displayed by bandwhich.
#[derive(Clone, Debug)]
pub struct Table {
Expand Down
Loading