Skip to content

Commit

Permalink
Move CallMethod trait, Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed May 3, 2023
1 parent 71b5507 commit 9ade909
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
40 changes: 0 additions & 40 deletions bindings/core/src/method_handler/call_method.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

#[cfg(not(target_family = "wasm"))]
use std::pin::Pin;

#[cfg(not(target_family = "wasm"))]
use futures::Future;
use iota_sdk::{
client::{secret::SecretManager, Client},
wallet::wallet::Wallet,
Expand All @@ -22,41 +17,6 @@ use crate::{
UtilsMethod,
};

#[cfg(not(target_family = "wasm"))]
pub trait CallMethod {
type Method;

// This uses a manual async_trait-like impl because it's not worth it to import the lib for one trait
fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>>;
}

#[cfg(not(target_family = "wasm"))]
impl CallMethod for Client {
type Method = ClientMethod;

fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>> {
Box::pin(call_client_method(self, method))
}
}

#[cfg(not(target_family = "wasm"))]
impl CallMethod for Wallet {
type Method = WalletMethod;

fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>> {
Box::pin(call_wallet_method(self, method))
}
}

#[cfg(not(target_family = "wasm"))]
impl CallMethod for SecretManager {
type Method = SecretManagerMethod;

fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>> {
Box::pin(call_secret_manager_method(self, method))
}
}

/// Call a client method.
pub async fn call_client_method(client: &Client, method: ClientMethod) -> Response {
log::debug!("Client method: {method:?}");
Expand Down
46 changes: 46 additions & 0 deletions bindings/core/src/method_handler/call_method_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use std::pin::Pin;

use futures::Future;
use iota_sdk::{
client::{secret::SecretManager, Client},
wallet::Wallet,
};

use crate::{
call_client_method, call_secret_manager_method, call_wallet_method, ClientMethod, Response, SecretManagerMethod,
WalletMethod,
};

pub trait CallMethod {
type Method;

// This uses a manual async_trait-like impl because it's not worth it to import the lib for one trait
fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>>;
}

impl CallMethod for Client {
type Method = ClientMethod;

fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>> {
Box::pin(call_client_method(self, method))
}
}

impl CallMethod for Wallet {
type Method = WalletMethod;

fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>> {
Box::pin(call_wallet_method(self, method))
}
}

impl CallMethod for SecretManager {
type Method = SecretManagerMethod;

fn call_method<'a>(&'a self, method: Self::Method) -> Pin<Box<dyn Future<Output = Response> + Send + 'a>> {
Box::pin(call_secret_manager_method(self, method))
}
}
6 changes: 4 additions & 2 deletions bindings/core/src/method_handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

mod account;
mod call_method;
#[cfg(not(target_family = "wasm"))]
mod call_method_trait;
mod client;
mod secret_manager;
mod utils;
mod wallet;

#[cfg(not(target_family = "wasm"))]
pub use call_method::CallMethod;
pub use call_method::{call_client_method, call_secret_manager_method, call_utils_method, call_wallet_method};
#[cfg(not(target_family = "wasm"))]
pub use call_method_trait::CallMethod;
#[cfg(feature = "mqtt")]
pub use client::listen_mqtt;
2 changes: 1 addition & 1 deletion sdk/src/wallet/wallet/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl WalletBuilder {
#[cfg(feature = "storage")]
let read_manager_builder = storage_manager.lock().await.get_wallet_data().await?;
#[cfg(not(feature = "storage"))]
let read_manager_builder: Option<WalletBuilder> = None;
let read_manager_builder: Option<Self> = None;

// Prioritize provided client_options and secret_manager over stored ones
let new_provided_client_options = if self.client_options.is_none() {
Expand Down

0 comments on commit 9ade909

Please sign in to comment.