From 6871407b1a2514c8c3b259a88cd5c267b206761e Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Wed, 12 Oct 2022 17:51:56 +0200 Subject: [PATCH] gui: clippification --- gui/src/app/cache.rs | 10 +--------- gui/src/app/mod.rs | 2 +- gui/src/app/state/mod.rs | 2 +- gui/src/app/view/home.rs | 2 +- gui/src/daemon/client/error.rs | 2 +- gui/src/daemon/client/jsonrpc.rs | 6 +++--- gui/src/main.rs | 12 ++++++------ gui/src/utils/mock.rs | 4 +++- gui/src/utils/sandbox.rs | 2 +- 9 files changed, 18 insertions(+), 24 deletions(-) diff --git a/gui/src/app/cache.rs b/gui/src/app/cache.rs index c403e043..39ede414 100644 --- a/gui/src/app/cache.rs +++ b/gui/src/app/cache.rs @@ -1,15 +1,7 @@ use crate::daemon::model::Coin; +#[derive(Default)] pub struct Cache { pub blockheight: i32, pub coins: Vec, } - -impl Default for Cache { - fn default() -> Self { - Self { - blockheight: 0, - coins: Vec::new(), - } - } -} diff --git a/gui/src/app/mod.rs b/gui/src/app/mod.rs index 79c29fbb..fa33403e 100644 --- a/gui/src/app/mod.rs +++ b/gui/src/app/mod.rs @@ -102,7 +102,7 @@ impl App { self.cache.coins = coins.clone(); } Message::BlockHeight(Ok(blockheight)) => { - self.cache.blockheight = blockheight.clone(); + self.cache.blockheight = *blockheight; } _ => {} }; diff --git a/gui/src/app/state/mod.rs b/gui/src/app/state/mod.rs index 6f2203bd..74ff0867 100644 --- a/gui/src/app/state/mod.rs +++ b/gui/src/app/state/mod.rs @@ -31,7 +31,7 @@ pub struct Home { } impl Home { - pub fn new(coins: &Vec) -> Self { + pub fn new(coins: &[Coin]) -> Self { Self { balance: Amount::from_sat(coins.iter().map(|coin| coin.amount.as_sat()).sum()), } diff --git a/gui/src/app/view/home.rs b/gui/src/app/view/home.rs index 17fb1107..23fd5763 100644 --- a/gui/src/app/view/home.rs +++ b/gui/src/app/view/home.rs @@ -7,7 +7,7 @@ use crate::ui::component::text::*; use super::message::Message; -pub fn home_view<'a>(balance: &'a bitcoin::Amount) -> Element<'a, Message> { +pub fn home_view(balance: &bitcoin::Amount) -> Element { column() .push(column().padding(40)) .push(text(&format!("{} BTC", balance.as_btc())).bold().size(50)) diff --git a/gui/src/daemon/client/error.rs b/gui/src/daemon/client/error.rs index eb5865f2..3d282fad 100644 --- a/gui/src/daemon/client/error.rs +++ b/gui/src/daemon/client/error.rs @@ -92,7 +92,7 @@ impl error::Error for Error { } } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] /// A JSONRPC error object pub struct RpcError { /// The integer identifier of the error diff --git a/gui/src/daemon/client/jsonrpc.rs b/gui/src/daemon/client/jsonrpc.rs index ca8a4eb4..6f511bde 100644 --- a/gui/src/daemon/client/jsonrpc.rs +++ b/gui/src/daemon/client/jsonrpc.rs @@ -113,7 +113,7 @@ impl JsonRPCClient { } } -#[derive(Debug, Clone, PartialEq, Serialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] /// A JSONRPC request object pub struct Request<'f, T: Serialize> { /// The name of the RPC call @@ -126,7 +126,7 @@ pub struct Request<'f, T: Serialize> { pub jsonrpc: &'f str, } -#[derive(Debug, Clone, PartialEq, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] /// A JSONRPC response object pub struct Response { /// A result if there is one, or null @@ -243,7 +243,7 @@ impl From for super::DaemonError { } } -#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] /// A JSONRPC error object pub struct RpcError { /// The integer identifier of the error diff --git a/gui/src/main.rs b/gui/src/main.rs index 349c92b5..13ccf16e 100644 --- a/gui/src/main.rs +++ b/gui/src/main.rs @@ -306,9 +306,9 @@ mod tests { #[test] fn test_parse_args() { - assert_eq!(true, parse_args(vec!["--meth".into()]).is_err()); - assert_eq!(true, parse_args(vec!["--datadir".into()]).is_err()); - assert_eq!(true, parse_args(vec!["--conf".into()]).is_err()); + assert!(parse_args(vec!["--meth".into()]).is_err()); + assert!(parse_args(vec!["--datadir".into()]).is_err()); + assert!(parse_args(vec!["--conf".into()]).is_err()); assert_eq!( Some(vec![ Arg::DatadirPath(PathBuf::from(".")), @@ -316,7 +316,7 @@ mod tests { ]), parse_args( "--datadir . --conf hello.toml" - .split(" ") + .split(' ') .map(|a| a.to_string()) .collect() ) @@ -333,7 +333,7 @@ mod tests { ]), parse_args( "--datadir hello --testnet" - .split(" ") + .split(' ') .map(|a| a.to_string()) .collect() ) @@ -346,7 +346,7 @@ mod tests { ]), parse_args( "--testnet --datadir hello" - .split(" ") + .split(' ') .map(|a| a.to_string()) .collect() ) diff --git a/gui/src/utils/mock.rs b/gui/src/utils/mock.rs index 05e3c01d..43e9e06b 100644 --- a/gui/src/utils/mock.rs +++ b/gui/src/utils/mock.rs @@ -9,9 +9,11 @@ use std::sync::{ }; use std::thread; +type TransportReceiver = Receiver>; + #[derive(Debug)] pub struct DaemonClient { - transport: Mutex<(Sender, Receiver>)>, + transport: Mutex<(Sender, TransportReceiver)>, } impl Client for DaemonClient { diff --git a/gui/src/utils/sandbox.rs b/gui/src/utils/sandbox.rs index 4c8defd2..7a408e0d 100644 --- a/gui/src/utils/sandbox.rs +++ b/gui/src/utils/sandbox.rs @@ -13,7 +13,7 @@ pub struct Sandbox { impl Sandbox { pub fn new(state: S) -> Self { - return Self { state }; + Self { state } } pub fn state(&self) -> &S {