From 72b5d9c3fdc0005de5710790ffc208b5da5b7bf9 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Tue, 24 Nov 2015 12:12:15 +0100 Subject: [PATCH] Removed unused trait --- src/cloud.rs | 2 +- src/device.rs | 26 ++++++++++++-------------- src/types.rs | 7 ------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/cloud.rs b/src/cloud.rs index cf28b96..95c60e9 100644 --- a/src/cloud.rs +++ b/src/cloud.rs @@ -10,7 +10,7 @@ use std::marker::PhantomData; use time::{Duration, SteadyTime, precise_time_ns}; use epoll; -use super::types::{Table, Protocol, VirtualInterface, Range, Error, NetworkId}; +use super::types::{Table, Protocol, Range, Error, NetworkId}; use super::device::Device; use super::udpmessage::{encode, decode, Options, Message}; use super::{ethernet, ip}; diff --git a/src/device.rs b/src/device.rs index dd9ac78..17fbc64 100644 --- a/src/device.rs +++ b/src/device.rs @@ -2,7 +2,7 @@ use std::os::unix::io::{AsRawFd, RawFd}; use std::io::{Result as IoResult, Error as IoError, Read, Write}; use std::fs; -use super::types::{Error, VirtualInterface, Type}; +use super::types::{Error, Type}; extern { fn setup_tap_device(fd: i32, ifname: *mut u8) -> i32; @@ -37,6 +37,17 @@ impl Device { pub fn ifname(&self) -> &str { &self.ifname } + + pub fn read(&mut self, mut buffer: &mut [u8]) -> Result { + self.fd.read(&mut buffer).map_err(|_| Error::TunTapDevError("Read error")) + } + + pub fn write(&mut self, data: &[u8]) -> Result<(), Error> { + match self.fd.write_all(&data) { + Ok(_) => Ok(()), + Err(_) => Err(Error::TunTapDevError("Write error")) + } + } } impl AsRawFd for Device { @@ -44,16 +55,3 @@ impl AsRawFd for Device { self.fd.as_raw_fd() } } - -impl VirtualInterface for Device { - fn read(&mut self, mut buffer: &mut [u8]) -> Result { - self.fd.read(&mut buffer).map_err(|_| Error::TunTapDevError("Read error")) - } - - fn write(&mut self, data: &[u8]) -> Result<(), Error> { - match self.fd.write_all(&data) { - Ok(_) => Ok(()), - Err(_) => Err(Error::TunTapDevError("Write error")) - } - } -} diff --git a/src/types.rs b/src/types.rs index 7557d9a..1a56862 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,7 +1,6 @@ use std::net::{SocketAddr, Ipv4Addr, Ipv6Addr}; use std::hash::Hasher; use std::{fmt, ptr}; -use std::os::unix::io::AsRawFd; use std::str::FromStr; use super::util::{as_bytes, as_obj}; @@ -113,12 +112,6 @@ pub trait Protocol: Sized { fn parse(&[u8]) -> Result<(Address, Address), Error>; } -pub trait VirtualInterface: AsRawFd { - fn read(&mut self, &mut [u8]) -> Result; - fn write(&mut self, &[u8]) -> Result<(), Error>; -} - - #[derive(Debug)] pub enum Error { ParseError(&'static str),