summary refs log tree commit diff
path: root/net_util
diff options
context:
space:
mode:
Diffstat (limited to 'net_util')
-rw-r--r--net_util/src/lib.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs
index 4dfcd39..790fbc3 100644
--- a/net_util/src/lib.rs
+++ b/net_util/src/lib.rs
@@ -6,7 +6,7 @@ extern crate libc;
 extern crate net_sys;
 extern crate sys_util;
 
-use std::fmt;
+use std::fmt::{self, Display};
 use std::fs::File;
 use std::io::{Read, Result as IoResult, Write};
 use std::mem;
@@ -34,6 +34,19 @@ pub enum Error {
 }
 pub type Result<T> = std::result::Result<T, Error>;
 
+impl Display for Error {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        use self::Error::*;
+
+        match self {
+            CreateSocket(e) => write!(f, "failed to create a socket: {}", e),
+            OpenTun(e) => write!(f, "failed to open /dev/net/tun: {}", e),
+            CreateTap(e) => write!(f, "failed to create tap interface: {}", e),
+            IoctlError(e) => write!(f, "ioctl failed: {}", e),
+        }
+    }
+}
+
 impl Error {
     pub fn sys_error(&self) -> SysError {
         match *self {
@@ -92,7 +105,7 @@ impl fmt::Display for MacAddressError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             MacAddressError::InvalidNumOctets(n) => write!(f, "invalid number of octets: {}", n),
-            MacAddressError::ParseOctet(ref e) => write!(f, "failed to parse octet: {:?}", e),
+            MacAddressError::ParseOctet(ref e) => write!(f, "failed to parse octet: {}", e),
         }
     }
 }
@@ -636,7 +649,7 @@ mod tests {
             // We won't have permission in test environments; allow that
             Ok(_t) => {}
             Err(Error::IoctlError(ref e)) if e.errno() == EPERM => {}
-            Err(e) => panic!("Unexpected Error:\n{:?}", e),
+            Err(e) => panic!("Unexpected Error:\n{}", e),
         }
     }
 }