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

Add explicit dyn keyword #395

Merged
merged 1 commit into from
Aug 5, 2019
Merged
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 src/toxcore/dht/packet/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl GetPayloadError {
}

impl Fail for GetPayloadError {
fn cause(&self) -> Option<&Fail> {
fn cause(&self) -> Option<&dyn Fail> {
Copy link
Member Author

@kpp kpp Aug 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kurnevsky did you miss that one error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it seems...

self.ctx.cause()
}

Expand Down
4 changes: 2 additions & 2 deletions src/toxcore/dht/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ struct ServerBootstrapInfo {
version: u32,
/// Callback to get the message of the day which will be sent with
/// `BootstrapInfo` packet.
motd_cb: Arc<Fn(&Server) -> Vec<u8> + Send + Sync>,
motd_cb: Arc<dyn Fn(&Server) -> Vec<u8> + Send + Sync>,
}

/**
Expand Down Expand Up @@ -1446,7 +1446,7 @@ impl Server {
}

/// Set toxcore version and message of the day callback.
pub fn set_bootstrap_info(&mut self, version: u32, motd_cb: Box<Fn(&Server) -> Vec<u8> + Send + Sync>) {
pub fn set_bootstrap_info(&mut self, version: u32, motd_cb: Box<dyn Fn(&Server) -> Vec<u8> + Send + Sync>) {
self.bootstrap_info = Some(ServerBootstrapInfo {
version,
motd_cb: motd_cb.into(),
Expand Down
4 changes: 2 additions & 2 deletions src/toxcore/dht/server_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ use crate::toxcore::stats::Stats;
/// Extension trait for running DHT server on `UdpSocket`.
pub trait ServerExt {
/// Run DHT server on `UdpSocket`.
fn run_socket(self, socket: UdpSocket, rx: Receiver<(Packet, SocketAddr)>, stats: Stats) -> Box<Future<Item = (), Error = Error> + Send>;
fn run_socket(self, socket: UdpSocket, rx: Receiver<(Packet, SocketAddr)>, stats: Stats) -> Box<dyn Future<Item = (), Error = Error> + Send>;
}

impl ServerExt for Server {
fn run_socket(self, socket: UdpSocket, rx: Receiver<(Packet, SocketAddr)>, stats: Stats) -> Box<Future<Item = (), Error = Error> + Send> {
fn run_socket(self, socket: UdpSocket, rx: Receiver<(Packet, SocketAddr)>, stats: Stats) -> Box<dyn Future<Item = (), Error = Error> + Send> {
let udp_addr = socket.local_addr()
.expect("Failed to get socket address");

Expand Down
2 changes: 1 addition & 1 deletion src/toxcore/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ macro_rules! error_kind {
}

impl failure::Fail for $error {
fn cause(&self) -> Option<&failure::Fail> {
fn cause(&self) -> Option<&dyn failure::Fail> {
self.ctx.cause()
}

Expand Down
4 changes: 2 additions & 2 deletions src/toxcore/io_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use std::io::{Error as IoError};
use futures::{Async, AsyncSink, Future, Poll, Sink, StartSend, Stream};

/// A convenience typedef around a `Future` whose error component is `io::Error`
pub type IoFuture<T> = Box<Future<Item = T, Error = IoError> + Send>;
pub type IoFuture<T> = Box<dyn Future<Item = T, Error = IoError> + Send>;

/// A convenience typedef around a `Stream` whose error component is `io::Error`
pub type IoStream<T> = Box<Stream<Item = T, Error = IoError> + Send>;
pub type IoStream<T> = Box<dyn Stream<Item = T, Error = IoError> + Send>;

/// Send item to a sink using reference
pub fn send_to<T: Send + 'static, Tx, E: Debug>(tx: &Tx, v: T) -> impl Future<Item=(), Error=E> + Send
Expand Down
8 changes: 4 additions & 4 deletions src/toxcore/tcp/server/server_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ pub trait ServerExt {
/// Running TCP ping sender and incoming `TcpStream`. This function uses
/// `tokio::spawn` inside so it should be executed via tokio to be able to
/// get tokio default executor.
fn run(self: Self, listner: TcpListener, dht_sk: SecretKey, stats: Stats, connections_limit: usize) -> Box<Future<Item = (), Error = ServerRunError> + Send>;
fn run(self: Self, listner: TcpListener, dht_sk: SecretKey, stats: Stats, connections_limit: usize) -> Box<dyn Future<Item = (), Error = ServerRunError> + Send>;
/// Running TCP server on incoming `TcpStream`
fn run_connection(self: Self, stream: TcpStream, dht_sk: SecretKey, stats: Stats) -> Box<Future<Item = (), Error = ConnectionError> + Send>;
fn run_connection(self: Self, stream: TcpStream, dht_sk: SecretKey, stats: Stats) -> Box<dyn Future<Item = (), Error = ConnectionError> + Send>;
}

impl ServerExt for Server {
fn run(self: Self, listner: TcpListener, dht_sk: SecretKey, stats: Stats, connections_limit: usize) -> Box<Future<Item = (), Error = ServerRunError> + Send> {
fn run(self: Self, listner: TcpListener, dht_sk: SecretKey, stats: Stats, connections_limit: usize) -> Box<dyn Future<Item = (), Error = ServerRunError> + Send> {
let connections_count = Arc::new(AtomicUsize::new(0));

let self_c = self.clone();
Expand Down Expand Up @@ -161,7 +161,7 @@ impl ServerExt for Server {
Box::new(future)
}

fn run_connection(self: Self, stream: TcpStream, dht_sk: SecretKey, stats: Stats) -> Box<Future<Item = (), Error = ConnectionError> + Send> {
fn run_connection(self: Self, stream: TcpStream, dht_sk: SecretKey, stats: Stats) -> Box<dyn Future<Item = (), Error = ConnectionError> + Send> {
let addr = match stream.peer_addr() {
Ok(addr) => addr,
Err(error) => return Box::new(future::err(ConnectionError::PeerAddrError {
Expand Down