Skip to content

Commit

Permalink
change derivative to reduce to fix clippy issues
Browse files Browse the repository at this point in the history
ref imsnif#303 (comment)

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>
  • Loading branch information
YJDoc2 committed Oct 9, 2024
1 parent 72219da commit 67cb063
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ After tests, check the formatting: `cargo fmt -- --check`

Note that at the moment the tests do not test the os layer (anything in the `os` folder).

If you are stuck, unsure about how to approach an issue or would like some guidance, you are welcome to contact: aram@poor.dev
If you are stuck, unsure about how to approach an issue or would like some guidance, you are welcome to [open an issue](https://github.com/imsnif/bandwhich/issues/new);
45 changes: 33 additions & 12 deletions Cargo.lock

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

6 changes: 4 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"] }
educe = { version = "0.6.0", default-features = false, features = ["Debug","Default"] }

[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
procfs = "0.17.0"
Expand All @@ -71,8 +71,9 @@ 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"
strum = { version = "0.26.3", features = ["derive"] }
educe = { version = "0.6.0", default-features = false, features = ["Debug","Default"] }


[target.'cfg(target_os = "windows")'.build-dependencies]
http_req = "0.12.0"
Expand All @@ -84,3 +85,4 @@ opt-level = 3
lto = "fat"
panic = "abort"
strip = "symbols"

8 changes: 4 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::{net::Ipv4Addr, path::PathBuf};

use clap::{Args, Parser, ValueEnum, ValueHint};
use clap_verbosity_flag::{InfoLevel, Verbosity};
use derivative::Derivative;
use educe::Educe;
use strum::EnumIter;

#[derive(Clone, Debug, Derivative, Parser)]
#[derivative(Default)]
#[derive(Clone, Debug, Educe, Parser)]
#[educe(Default)]
#[command(name = "bandwhich", version)]
pub struct Opt {
#[arg(short, long)]
Expand Down Expand Up @@ -34,7 +34,7 @@ pub struct Opt {
pub log_to: Option<PathBuf>,

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

#[command(flatten)]
Expand Down
18 changes: 12 additions & 6 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 educe::Educe;

use crate::cli::UnitFamily;

#[derive(Copy, Clone, Derivative)]
#[derivative(Debug)]
#[derive(Copy, Clone, Educe)]
#[educe(Debug)]
pub struct DisplayBandwidth {
#[derivative(Debug(format_with = "fmt_f64"))]
#[educe(Debug(method(fmt_f64)))]
pub bandwidth: f64,
pub unit_family: BandwidthUnitFamily,
}
Expand All @@ -28,9 +28,15 @@ fn fmt_f64(val: &f64, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
}

/// Type wrapper around [`UnitFamily`] to provide extra functionality.
#[derive(Copy, Clone, Derivative, Default, Eq, PartialEq)]
#[derivative(Debug = "transparent")]
#[derive(Copy, Clone, Default, Eq, PartialEq)]
pub struct BandwidthUnitFamily(UnitFamily);

impl std::fmt::Debug for BandwidthUnitFamily {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
write!(fmt, "{:?}", self.0)
}
}

impl From<UnitFamily> for BandwidthUnitFamily {
fn from(value: UnitFamily) -> Self {
Self(value)
Expand Down
8 changes: 4 additions & 4 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 derivative::Derivative;
use educe::Educe;
use itertools::Itertools;
use ratatui::{
layout::{Constraint, Rect},
Expand Down Expand Up @@ -165,8 +165,8 @@ 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, Educe)]
#[educe(Debug)]
struct NColsTableData<const C: usize> {
/// The name of each column.
column_names: [&'static str; C],
Expand All @@ -176,7 +176,7 @@ 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>"))]
#[educe(Debug(method(debug_fn::<C>)))]
column_selector: Rc<ColumnSelectorFn>,
}

Expand Down

0 comments on commit 67cb063

Please sign in to comment.