Skip to content

Commit

Permalink
revert Box<dyn Error> to String conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
jxs committed Jul 8, 2023
1 parent 3f3f745 commit 87f58c3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
8 changes: 6 additions & 2 deletions protocols/upnp/src/gateway.rs
Expand Up @@ -64,10 +64,14 @@ pub trait Gateway: Sized + Send + Sync {
protocol: Protocol,
addr: SocketAddrV4,
duration: Duration,
) -> Result<(), String>;
) -> Result<(), Box<dyn Error + Send + Sync + 'static>>;

/// Remove port mapping on the gateway.
async fn remove_port(_: Arc<Self>, protocol: Protocol, port: u16) -> Result<(), String>;
async fn remove_port(
_: Arc<Self>,
protocol: Protocol,
port: u16,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>>;

// /// Spawn a future on the executor.
fn spawn<F>(f: F)
Expand Down
12 changes: 8 additions & 4 deletions protocols/upnp/src/gateway/async_std.rs
Expand Up @@ -53,7 +53,7 @@ impl super::Gateway for Gateway {
protocol: Protocol,
addr: SocketAddrV4,
duration: Duration,
) -> Result<(), String> {
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
Expand All @@ -67,18 +67,22 @@ impl super::Gateway for Gateway {
"rust-libp2p mapping",
)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}

async fn remove_port(gateway: Arc<Self>, protocol: Protocol, port: u16) -> Result<(), String> {
async fn remove_port(
gateway: Arc<Self>,
protocol: Protocol,
port: u16,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
};
gateway
.remove_port(protocol, port)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}
fn spawn<F>(f: F)
where
Expand Down
12 changes: 8 additions & 4 deletions protocols/upnp/src/gateway/tokio.rs
Expand Up @@ -53,7 +53,7 @@ impl super::Gateway for Gateway {
protocol: Protocol,
addr: SocketAddrV4,
duration: Duration,
) -> Result<(), String> {
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
Expand All @@ -67,18 +67,22 @@ impl super::Gateway for Gateway {
"rust-libp2p mapping",
)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}

async fn remove_port(gateway: Arc<Self>, protocol: Protocol, port: u16) -> Result<(), String> {
async fn remove_port(
gateway: Arc<Self>,
protocol: Protocol,
port: u16,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let protocol = match protocol {
Protocol::Tcp => PortMappingProtocol::TCP,
Protocol::Udp => PortMappingProtocol::UDP,
};
gateway
.remove_port(protocol, port)
.await
.map_err(|err| err.to_string())
.map_err(|err| err.into())
}

fn spawn<F>(f: F)
Expand Down

0 comments on commit 87f58c3

Please sign in to comment.