Skip to content

Commit

Permalink
use 'Self' keyword to refer to own type
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Nov 2, 2022
1 parent 2a844ea commit 9c6358e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
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
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

0 comments on commit 9c6358e

Please sign in to comment.