Skip to content

Commit

Permalink
Use dyn trait
Browse files Browse the repository at this point in the history
Use the new syntax from Rust 1.27 for using trait objects.
  • Loading branch information
rom1v committed Dec 12, 2018
1 parent 6053900 commit 7a8a049
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions relay-rust/src/adb_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where
}
}
pub struct AdbMonitor {
callback: Box<AdbMonitorCallback>,
callback: Box<dyn AdbMonitorCallback>,
buf: ByteBuffer,
connected_devices: Vec<String>,
}
Expand All @@ -49,7 +49,7 @@ impl AdbMonitor {
const RETRY_DELAY_ADB_DAEMON_OK: u64 = 1000;
const RETRY_DELAY_ADB_DAEMON_KO: u64 = 5000;

pub fn new(callback: Box<AdbMonitorCallback>) -> Self {
pub fn new(callback: Box<dyn AdbMonitorCallback>) -> Self {
Self {
callback,
buf: ByteBuffer::new(Self::BUFFER_SIZE),
Expand Down
4 changes: 2 additions & 2 deletions relay-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ fn print_usage() {
eprint!("{}", msg);
}

fn append_command_usage(msg: &mut String, command: &Command) {
fn append_command_usage(msg: &mut String, command: &dyn Command) {
msg.push_str(" gnirehtet ");
msg.push_str(command.command());
let accepted_parameters = command.accepted_parameters();
Expand All @@ -556,7 +556,7 @@ fn append_command_usage(msg: &mut String, command: &Command) {
}
}

fn print_command_usage(command: &Command) {
fn print_command_usage(command: &dyn Command) {
let mut msg = String::new();
append_command_usage(&mut msg, command);
eprint!("{}", msg);
Expand Down
8 changes: 4 additions & 4 deletions relay-rust/src/relay/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ pub struct Client {
client_to_network: Ipv4PacketBuffer,
network_to_client: StreamBuffer,
router: Router,
close_listener: Box<CloseListener<Client>>,
close_listener: Box<dyn CloseListener<Client>>,
closed: bool,
pending_packet_sources: Vec<Rc<RefCell<PacketSource>>>,
pending_packet_sources: Vec<Rc<RefCell<dyn PacketSource>>>,
// number of remaining bytes of "id" to send to the client before relaying any data
pending_id_bytes: usize,
}
Expand Down Expand Up @@ -113,7 +113,7 @@ impl Client {
id: u32,
selector: &mut Selector,
stream: TcpStream,
close_listener: Box<CloseListener<Client>>,
close_listener: Box<dyn CloseListener<Client>>,
) -> io::Result<Rc<RefCell<Self>>> {
// on start, we are interested only in writing (we must first send the client id)
let interests = Ready::writable();
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Client {
}
}

pub fn register_pending_packet_source(&mut self, source: Rc<RefCell<PacketSource>>) {
pub fn register_pending_packet_source(&mut self, source: Rc<RefCell<dyn PacketSource>>) {
self.pending_packet_sources.push(source);
}

Expand Down
6 changes: 3 additions & 3 deletions relay-rust/src/relay/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const TAG: &str = "Router";
pub struct Router {
client: Weak<RefCell<Client>>,
// there are typically only few connections per client, HashMap would be less efficient
connections: Vec<Rc<RefCell<Connection>>>,
connections: Vec<Rc<RefCell<dyn Connection>>>,
}

impl Router {
Expand Down Expand Up @@ -114,7 +114,7 @@ impl Router {
id: ConnectionId,
client: Weak<RefCell<Client>>,
ipv4_packet: &Ipv4Packet,
) -> io::Result<Rc<RefCell<Connection>>> {
) -> io::Result<Rc<RefCell<dyn Connection>>> {
let (ipv4_header, transport_header) = ipv4_packet.headers();
let transport_header = transport_header.expect("No transport");
match id.protocol() {
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Router {
.position(|connection| connection.borrow().id() == id)
}

pub fn remove(&mut self, connection: &Connection) {
pub fn remove(&mut self, connection: &dyn Connection) {
let index = self
.connections
.iter()
Expand Down
2 changes: 1 addition & 1 deletion relay-rust/src/relay/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ where

pub struct Selector {
poll: Poll,
handlers: Slab<Rc<EventHandler>>,
handlers: Slab<Rc<dyn EventHandler>>,
// tokens to be removed after all the current poll events are executed
tokens_to_remove: Vec<Token>,
}
Expand Down

0 comments on commit 7a8a049

Please sign in to comment.