Skip to content

Commit

Permalink
Clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjemmmic committed Jun 24, 2024
1 parent 82f93f2 commit 70efe66
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 73 deletions.
7 changes: 4 additions & 3 deletions async_ip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::fmt::Formatter;
use std::net::IpAddr;
#[cfg(not(target_family = "wasm"))]
use std::net::SocketAddr;
Expand Down Expand Up @@ -190,10 +191,10 @@ pub enum IpRetrieveError {
Error(String),
}

impl ToString for IpRetrieveError {
fn to_string(&self) -> String {
impl std::fmt::Display for IpRetrieveError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
IpRetrieveError::Error(err) => err.to_string(),
IpRetrieveError::Error(err) => write!(f, "{}", err),
}
}
}
24 changes: 14 additions & 10 deletions citadel_wire/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Formatter;
use tokio::io::Error;

#[derive(Debug)]
Expand All @@ -16,16 +17,19 @@ impl FirewallError {
}
}

impl ToString for FirewallError {
fn to_string(&self) -> String {
match self {
FirewallError::UPNP(err) => err.to_string(),
FirewallError::HolePunch(err) => err.to_string(),
FirewallError::NotApplicable => "Method not applicable to local node".to_string(),
FirewallError::HolePunchExhausted => "No more NAT traversal methods exist".to_string(),
FirewallError::LocalIPAddrFail => "Unable to obtain local IP info".to_string(),
FirewallError::Skip => "Skipped".to_string(),
}
impl std::fmt::Display for FirewallError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
FirewallError::UPNP(err) | FirewallError::HolePunch(err) => err,
FirewallError::NotApplicable => "Method not applicable to local node",
FirewallError::HolePunchExhausted => "No more NAT traversal methods exist",
FirewallError::LocalIPAddrFail => "Unable to obtain local IP info",
FirewallError::Skip => "Skipped",
}
)
}
}

Expand Down
60 changes: 30 additions & 30 deletions netbeam/src/sync/network_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,37 +141,43 @@ impl<K: MultiplexedConnKey + 'static> MultiplexedConn<K> {
}

/// Both nodes execute a function, returning once one of the functions gets evaluated
pub fn net_select<'a, F: Send + 'a, R: Send + 'a>(&'a self, future: F) -> NetSelect<'a, R>
where
F: Future<Output = R>,
{
pub fn net_select<'a, F: Future<Output = R> + Send + 'a, R: Send + 'a>(
&'a self,
future: F,
) -> NetSelect<'a, R> {
NetSelect::new(self, self.node_type(), future)
}

/// Both nodes execute a function, returning once one of the nodes achieves an Ok result
pub fn net_select_ok<'a, F: Send + 'a, R: Send + 'a>(&'a self, future: F) -> NetSelectOk<'a, R>
where
F: Future<Output = Result<R, anyhow::Error>>,
{
pub fn net_select_ok<
'a,
F: Future<Output = Result<R, anyhow::Error>> + Send + 'a,
R: Send + 'a,
>(
&'a self,
future: F,
) -> NetSelectOk<'a, R> {
NetSelectOk::new(self, self.node_type(), future)
}

/// Both nodes execute a function, returning the output once both nodes finish the operation
pub fn net_join<'a, F: Send + 'a, R: Send + 'a>(&'a self, future: F) -> NetJoin<'a, R>
where
F: Future<Output = R>,
{
pub fn net_join<'a, F: Future<Output = R> + Send + 'a, R: Send + 'a>(
&'a self,
future: F,
) -> NetJoin<'a, R> {
NetJoin::new(self, self.node_type(), future)
}

/// Both nodes attempt to execute a fallible function. Returns once both functions return Ok, or, when one returns an error
pub fn net_try_join<'a, F: Send + 'a, R: Send + 'a, E: Send + 'a>(
pub fn net_try_join<
'a,
F: Future<Output = Result<R, E>> + Send + 'a,
R: Send + 'a,
E: Send + 'a,
>(
&'a self,
future: F,
) -> NetTryJoin<'a, R, E>
where
F: Future<Output = Result<R, E>>,
{
) -> NetTryJoin<'a, R, E> {
NetTryJoin::new(self, self.node_type(), future)
}

Expand All @@ -181,32 +187,26 @@ impl<K: MultiplexedConnKey + 'static> MultiplexedConn<K> {
}

/// Returns the payload to the adjacent node at about the same time. This node receives the payload sent by the adjacent node (exchange)
pub fn sync_exchange_payload<'a, R: 'a>(&'a self, payload: R) -> NetSyncStart<'a, R>
where
R: Serialize + DeserializeOwned + Send + Sync,
{
pub fn sync_exchange_payload<'a, R: Serialize + DeserializeOwned + Send + Sync + 'a>(
&'a self,
payload: R,
) -> NetSyncStart<'a, R> {
NetSyncStart::exchange_payload(self, self.node_type(), payload)
}

/// Executes a function at about the same time as the adjacent node
/// - payload: an element to exchange with the opposite node
pub fn sync_execute<
'a,
F: 'a,
Fx: 'a,
F: Future<Output = R> + Send + 'a,
Fx: FnOnce(P) -> F + Send + 'a,
P: Serialize + DeserializeOwned + Send + Sync + 'a,
R: 'a,
>(
&'a self,
future: Fx,
payload: P,
) -> NetSyncStart<'a, R>
where
F: Future<Output = R>,
F: Send,
Fx: FnOnce(P) -> F,
Fx: Send,
{
) -> NetSyncStart<'a, R> {
NetSyncStart::new(self, self.node_type(), future, payload)
}

Expand Down
7 changes: 2 additions & 5 deletions netbeam/src/sync/operations/net_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ impl<'a, T: Send + 'a> NetJoin<'a, T> {
S: Subscribable<ID = K, UnderlyingConn = Conn>,
K: MultiplexedConnKey + 'a,
Conn: ReliableOrderedStreamToTarget + 'static,
F: Send + 'a,
F: Future<Output = T> + Send + 'a,
>(
conn: &'a S,
local_node_type: RelativeNodeType,
future: F,
) -> Self
where
F: Future<Output = T>,
{
) -> Self {
// we can safely unwrap since we are wrapping the result in an Ok()
Self {
future: Box::pin(
Expand Down
7 changes: 2 additions & 5 deletions netbeam/src/sync/operations/net_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ impl<'a, R: Send + 'a> NetSelect<'a, R> {
S: Subscribable<ID = K, UnderlyingConn = Conn>,
K: MultiplexedConnKey + 'a,
Conn: ReliableOrderedStreamToTarget + 'static,
F: Send + 'a,
F: Future<Output = R> + Send + 'a,
>(
conn: &'a S,
local_node_type: RelativeNodeType,
future: F,
) -> Self
where
F: Future<Output = R>,
{
) -> Self {
Self {
future: Box::pin(
NetSelectOk::new(conn, local_node_type, future.map(Ok))
Expand Down
7 changes: 2 additions & 5 deletions netbeam/src/sync/operations/net_select_ok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ impl<'a, R: Send + 'a> NetSelectOk<'a, R> {
S: Subscribable<ID = K, UnderlyingConn = Conn>,
K: MultiplexedConnKey + 'a,
Conn: ReliableOrderedStreamToTarget + 'static,
F: Send + 'a,
F: Future<Output = Result<R, anyhow::Error>> + Send + 'a,
>(
conn: &'a S,
local_node_type: RelativeNodeType,
future: F,
) -> Self
where
F: Future<Output = Result<R, anyhow::Error>>,
{
) -> Self {
Self {
future: Box::pin(resolve(conn, local_node_type, future)),
}
Expand Down
7 changes: 2 additions & 5 deletions netbeam/src/sync/operations/net_try_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ impl<'a, T: Send + 'a, E: Send + 'a> NetTryJoin<'a, T, E> {
S: Subscribable<ID = K, UnderlyingConn = Conn>,
K: MultiplexedConnKey + 'a,
Conn: ReliableOrderedStreamToTarget + 'static,
F: Send + 'a,
F: Future<Output = Result<T, E>> + Send + 'a,
>(
conn: &'a S,
local_node_type: RelativeNodeType,
future: F,
) -> NetTryJoin<'a, T, E>
where
F: Future<Output = Result<T, E>>,
{
) -> NetTryJoin<'a, T, E> {
Self {
future: Box::pin(resolve(conn, local_node_type, future)),
}
Expand Down
2 changes: 1 addition & 1 deletion netbeam/src/sync/primitives/net_rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ async fn passive_background_handler<S: Subscribable + 'static, T: NetObject>(
LockType::Read => {
// load inside local map to allow instant local read access
let lock = Some(Arc::new(lock));
*read_lock_local.write() = lock.clone();
read_lock_local.write().clone_from(&lock);
LocalLockHolder::Read(lock, true)
}

Expand Down
12 changes: 3 additions & 9 deletions netbeam/src/sync/sync_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,15 @@ impl<'a, R: 'a> NetSyncStart<'a, R> {
S: Subscribable<ID = K, UnderlyingConn = Conn>,
K: MultiplexedConnKey + 'a,
Conn: ReliableOrderedStreamToTarget + 'static,
F: 'a,
Fx: 'a,
F: Future<Output = R> + Send + 'a,
Fx: FnOnce(P) -> F + Send + 'a,
P: Serialize + DeserializeOwned + Send + Sync + 'a,
>(
conn: &'a S,
relative_node_type: RelativeNodeType,
future: Fx,
payload: P,
) -> Self
where
F: Future<Output = R>,
F: Send,
Fx: FnOnce(P) -> F,
Fx: Send,
{
) -> Self {
Self {
future: Box::pin(synchronize(conn, relative_node_type, future, payload)),
}
Expand Down

0 comments on commit 70efe66

Please sign in to comment.