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

Clippy/use self #184

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion examples/binance_save_all_trades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn save_all_trades_websocket() {

impl WebSocketHandler {
pub fn new(local_wrt: Writer<File>) -> Self {
WebSocketHandler { wrt: local_wrt }
Self { wrt: local_wrt }
}

// serialize DayTickerEvent as CSV records
Expand Down
44 changes: 22 additions & 22 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub enum Futures {

impl From<API> for String {
fn from(item: API) -> Self {
String::from(match item {
Self::from(match item {
API::Spot(route) => match route {
Spot::Ping => "/api/v3/ping",
Spot::Time => "/api/v3/time",
Expand Down Expand Up @@ -170,28 +170,28 @@ pub trait Binance {
}

impl Binance for General {
fn new(api_key: Option<String>, secret_key: Option<String>) -> General {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Self {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> General {
General {
) -> Self {
Self {
client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()),
}
}
}

impl Binance for Account {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Account {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Self {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> Account {
Account {
) -> Self {
Self {
client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()),
recv_window: config.recv_window,
}
Expand All @@ -214,29 +214,29 @@ impl Binance for Savings {
}

impl Binance for Market {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Market {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Self {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> Market {
Market {
) -> Self {
Self {
client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()),
recv_window: config.recv_window,
}
}
}

impl Binance for UserStream {
fn new(api_key: Option<String>, secret_key: Option<String>) -> UserStream {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Self {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> UserStream {
UserStream {
) -> Self {
Self {
client: Client::new(api_key, secret_key, config.rest_api_endpoint.clone()),
recv_window: config.recv_window,
}
Expand All @@ -248,14 +248,14 @@ impl Binance for UserStream {
// *****************************************************

impl Binance for FuturesGeneral {
fn new(api_key: Option<String>, secret_key: Option<String>) -> FuturesGeneral {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Self {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> FuturesGeneral {
FuturesGeneral {
) -> Self {
Self {
client: Client::new(
api_key,
secret_key,
Expand All @@ -266,14 +266,14 @@ impl Binance for FuturesGeneral {
}

impl Binance for FuturesMarket {
fn new(api_key: Option<String>, secret_key: Option<String>) -> FuturesMarket {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Self {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> FuturesMarket {
FuturesMarket {
) -> Self {
Self {
client: Client::new(
api_key,
secret_key,
Expand Down Expand Up @@ -304,14 +304,14 @@ impl Binance for FuturesAccount {
}

impl Binance for FuturesUserStream {
fn new(api_key: Option<String>, secret_key: Option<String>) -> FuturesUserStream {
fn new(api_key: Option<String>, secret_key: Option<String>) -> Self {
Self::new_with_config(api_key, secret_key, &Config::default())
}

fn new_with_config(
api_key: Option<String>, secret_key: Option<String>, config: &Config,
) -> FuturesUserStream {
FuturesUserStream {
) -> Self {
Self {
client: Client::new(
api_key,
secret_key,
Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct Client {

impl Client {
pub fn new(api_key: Option<String>, secret_key: Option<String>, host: String) -> Self {
Client {
Self {
api_key: api_key.unwrap_or_default(),
secret_key: secret_key.unwrap_or_default(),
host,
Expand Down
10 changes: 5 additions & 5 deletions src/futures/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ pub enum ContractType {
impl From<ContractType> for String {
fn from(item: ContractType) -> Self {
match item {
ContractType::Perpetual => String::from("PERPETUAL"),
ContractType::CurrentMonth => String::from("CURRENT_MONTH"),
ContractType::NextMonth => String::from("NEXT_MONTH"),
ContractType::CurrentQuarter => String::from("CURRENT_QUARTER"),
ContractType::NextQuarter => String::from("NEXT_QUARTER"),
ContractType::Perpetual => Self::from("PERPETUAL"),
ContractType::CurrentMonth => Self::from("CURRENT_MONTH"),
ContractType::NextMonth => Self::from("NEXT_MONTH"),
ContractType::CurrentQuarter => Self::from("CURRENT_QUARTER"),
ContractType::NextQuarter => Self::from("NEXT_QUARTER"),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/futures/websockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ impl FuturesWebsocketAPI {
};

match self {
FuturesWebsocketAPI::Default => {
Self::Default => {
format!("{}/ws/{}", baseurl, subscription)
}
FuturesWebsocketAPI::MultiStream => {
Self::MultiStream => {
format!("{}/stream?streams={}", baseurl, subscription)
}
FuturesWebsocketAPI::Custom(url) => url,
Self::Custom(url) => url,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
clippy::manual_string_new,
clippy::single_match_else,
clippy::implicit_clone,
clippy::semicolon_if_nothing_returned
clippy::semicolon_if_nothing_returned,
clippy::use_self
)]

mod client;
Expand Down
4 changes: 2 additions & 2 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ pub struct Bids {
}

impl Bids {
pub fn new(price: f64, qty: f64) -> Bids {
Bids { price, qty }
pub fn new(price: f64, qty: f64) -> Self {
Self { price, qty }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/websockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ enum WebsocketAPI {
impl WebsocketAPI {
fn params(self, subscription: &str) -> String {
match self {
WebsocketAPI::Default => format!("wss://stream.binance.com:9443/ws/{}", subscription),
WebsocketAPI::MultiStream => format!(
Self::Default => format!("wss://stream.binance.com:9443/ws/{}", subscription),
Self::MultiStream => format!(
"wss://stream.binance.com:9443/stream?streams={}",
subscription
),
WebsocketAPI::Custom(url) => format!("{}/{}", url, subscription),
Self::Custom(url) => format!("{}/{}", url, subscription),
}
}
}
Expand Down