about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/fs.rs68
-rw-r--r--src/libstd/io/mod.rs14
-rw-r--r--src/libstd/io/net/addrinfo.rs10
-rw-r--r--src/libstd/io/net/ip.rs8
-rw-r--r--src/libstd/io/process.rs15
-rw-r--r--src/libstd/io/stdio.rs2
6 files changed, 69 insertions, 48 deletions
diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs
index 0fffb2fafbe..1556ef43eb7 100644
--- a/src/libstd/io/fs.rs
+++ b/src/libstd/io/fs.rs
@@ -107,7 +107,7 @@ impl File {
     ///
     /// let file = match File::open_mode(&p, Open, ReadWrite) {
     ///     Ok(f) => f,
-    ///     Err(e) => panic!("file error: {}", e),
+    ///     Err(e) => panic!("file error: {:?}", e),
     /// };
     /// // do some stuff with that file
     ///
@@ -156,7 +156,7 @@ impl File {
                 })
             }
         }).update_err("couldn't open path as file", |e| {
-            format!("{}; path={}; mode={}; access={}", e, path.display(),
+            format!("{:?}; path={:?}; mode={}; access={}", e, path.display(),
                 mode_string(mode), access_string(access))
         })
     }
@@ -211,7 +211,7 @@ impl File {
     pub fn fsync(&mut self) -> IoResult<()> {
         self.fd.fsync()
             .update_err("couldn't fsync file",
-                        |e| format!("{}; path={}", e, self.path.display()))
+                        |e| format!("{:?}; path={:?}", e, self.path.display()))
     }
 
     /// This function is similar to `fsync`, except that it may not synchronize
@@ -221,7 +221,7 @@ impl File {
     pub fn datasync(&mut self) -> IoResult<()> {
         self.fd.datasync()
             .update_err("couldn't datasync file",
-                        |e| format!("{}; path={}", e, self.path.display()))
+                        |e| format!("{:?}; path={:?}", e, self.path.display()))
     }
 
     /// Either truncates or extends the underlying file, updating the size of
@@ -235,7 +235,7 @@ impl File {
     pub fn truncate(&mut self, size: i64) -> IoResult<()> {
         self.fd.truncate(size)
             .update_err("couldn't truncate file", |e|
-                format!("{}; path={}; size={}", e, self.path.display(), size))
+                format!("{:?}; path={:?}; size={:?}", e, self.path.display(), size))
     }
 
     /// Returns true if the stream has reached the end of the file.
@@ -255,7 +255,7 @@ impl File {
     pub fn stat(&self) -> IoResult<FileStat> {
         self.fd.fstat()
             .update_err("couldn't fstat file", |e|
-                format!("{}; path={}", e, self.path.display()))
+                format!("{:?}; path={:?}", e, self.path.display()))
     }
 }
 
@@ -283,7 +283,7 @@ impl File {
 pub fn unlink(path: &Path) -> IoResult<()> {
     fs_imp::unlink(path)
            .update_err("couldn't unlink path", |e|
-               format!("{}; path={}", e, path.display()))
+               format!("{:?}; path={:?}", e, path.display()))
 }
 
 /// Given a path, query the file system to get information about a file,
@@ -310,7 +310,7 @@ pub fn unlink(path: &Path) -> IoResult<()> {
 pub fn stat(path: &Path) -> IoResult<FileStat> {
     fs_imp::stat(path)
            .update_err("couldn't stat path", |e|
-               format!("{}; path={}", e, path.display()))
+               format!("{:?}; path={:?}", e, path.display()))
 }
 
 /// Perform the same operation as the `stat` function, except that this
@@ -324,7 +324,7 @@ pub fn stat(path: &Path) -> IoResult<FileStat> {
 pub fn lstat(path: &Path) -> IoResult<FileStat> {
     fs_imp::lstat(path)
            .update_err("couldn't lstat path", |e|
-               format!("{}; path={}", e, path.display()))
+               format!("{:?}; path={:?}", e, path.display()))
 }
 
 /// Rename a file or directory to a new name.
@@ -346,7 +346,7 @@ pub fn lstat(path: &Path) -> IoResult<FileStat> {
 pub fn rename(from: &Path, to: &Path) -> IoResult<()> {
     fs_imp::rename(from, to)
            .update_err("couldn't rename path", |e|
-               format!("{}; from={}; to={}", e, from.display(), to.display()))
+               format!("{:?}; from={:?}; to={:?}", e, from.display(), to.display()))
 }
 
 /// Copies the contents of one file to another. This function will also
@@ -380,7 +380,7 @@ pub fn rename(from: &Path, to: &Path) -> IoResult<()> {
 pub fn copy(from: &Path, to: &Path) -> IoResult<()> {
     fn update_err<T>(result: IoResult<T>, from: &Path, to: &Path) -> IoResult<T> {
         result.update_err("couldn't copy path", |e| {
-            format!("{}; from={}; to={}", e, from.display(), to.display())
+            format!("{:?}; from={:?}; to={:?}", e, from.display(), to.display())
         })
     }
 
@@ -424,14 +424,14 @@ pub fn copy(from: &Path, to: &Path) -> IoResult<()> {
 pub fn chmod(path: &Path, mode: io::FilePermission) -> IoResult<()> {
     fs_imp::chmod(path, mode.bits() as uint)
            .update_err("couldn't chmod path", |e|
-               format!("{}; path={}; mode={}", e, path.display(), mode))
+               format!("{:?}; path={:?}; mode={:?}", e, path.display(), mode))
 }
 
 /// Change the user and group owners of a file at the specified path.
 pub fn chown(path: &Path, uid: int, gid: int) -> IoResult<()> {
     fs_imp::chown(path, uid, gid)
            .update_err("couldn't chown path", |e|
-               format!("{}; path={}; uid={}; gid={}", e, path.display(), uid, gid))
+               format!("{:?}; path={:?}; uid={:?}; gid={:?}", e, path.display(), uid, gid))
 }
 
 /// Creates a new hard link on the filesystem. The `dst` path will be a
@@ -440,7 +440,7 @@ pub fn chown(path: &Path, uid: int, gid: int) -> IoResult<()> {
 pub fn link(src: &Path, dst: &Path) -> IoResult<()> {
     fs_imp::link(src, dst)
            .update_err("couldn't link path", |e|
-               format!("{}; src={}; dest={}", e, src.display(), dst.display()))
+               format!("{:?}; src={:?}; dest={:?}", e, src.display(), dst.display()))
 }
 
 /// Creates a new symbolic link on the filesystem. The `dst` path will be a
@@ -448,7 +448,7 @@ pub fn link(src: &Path, dst: &Path) -> IoResult<()> {
 pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> {
     fs_imp::symlink(src, dst)
            .update_err("couldn't symlink path", |e|
-               format!("{}; src={}; dest={}", e, src.display(), dst.display()))
+               format!("{:?}; src={:?}; dest={:?}", e, src.display(), dst.display()))
 }
 
 /// Reads a symlink, returning the file that the symlink points to.
@@ -460,7 +460,7 @@ pub fn symlink(src: &Path, dst: &Path) -> IoResult<()> {
 pub fn readlink(path: &Path) -> IoResult<Path> {
     fs_imp::readlink(path)
            .update_err("couldn't resolve symlink for path", |e|
-               format!("{}; path={}", e, path.display()))
+               format!("{:?}; path={:?}", e, path.display()))
 }
 
 /// Create a new, empty directory at the provided path
@@ -483,7 +483,7 @@ pub fn readlink(path: &Path) -> IoResult<Path> {
 pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> {
     fs_imp::mkdir(path, mode.bits() as uint)
            .update_err("couldn't create directory", |e|
-               format!("{}; path={}; mode={}", e, path.display(), mode))
+               format!("{:?}; path={:?}; mode={:?}", e, path.display(), mode))
 }
 
 /// Remove an existing, empty directory
@@ -505,7 +505,7 @@ pub fn mkdir(path: &Path, mode: FilePermission) -> IoResult<()> {
 pub fn rmdir(path: &Path) -> IoResult<()> {
     fs_imp::rmdir(path)
            .update_err("couldn't remove directory", |e|
-               format!("{}; path={}", e, path.display()))
+               format!("{:?}; path={:?}", e, path.display()))
 }
 
 /// Retrieve a vector containing all entries within a provided directory
@@ -545,7 +545,7 @@ pub fn rmdir(path: &Path) -> IoResult<()> {
 pub fn readdir(path: &Path) -> IoResult<Vec<Path>> {
     fs_imp::readdir(path)
            .update_err("couldn't read directory",
-                       |e| format!("{}; path={}", e, path.display()))
+                       |e| format!("{:?}; path={:?}", e, path.display()))
 }
 
 /// Returns an iterator that will recursively walk the directory structure
@@ -555,7 +555,7 @@ pub fn readdir(path: &Path) -> IoResult<Vec<Path>> {
 pub fn walk_dir(path: &Path) -> IoResult<Directories> {
     Ok(Directories {
         stack: try!(readdir(path).update_err("couldn't walk directory",
-                                             |e| format!("{}; path={}", e, path.display())))
+                                             |e| format!("{:?}; path={:?}", e, path.display())))
     })
 }
 
@@ -605,7 +605,7 @@ pub fn mkdir_recursive(path: &Path, mode: FilePermission) -> IoResult<()> {
 
         let result = mkdir(&curpath, mode)
             .update_err("couldn't recursively mkdir",
-                        |e| format!("{}; path={}", e, path.display()));
+                        |e| format!("{:?}; path={:?}", e, path.display()));
 
         match result {
             Err(mkdir_err) => {
@@ -632,7 +632,7 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> {
     rm_stack.push(path.clone());
 
     fn rmdir_failed(err: &IoError, path: &Path) -> String {
-        format!("rmdir_recursive failed; path={}; cause={}",
+        format!("rmdir_recursive failed; path={:?}; cause={:?}",
                 path.display(), err)
     }
 
@@ -692,14 +692,14 @@ pub fn rmdir_recursive(path: &Path) -> IoResult<()> {
 pub fn change_file_times(path: &Path, atime: u64, mtime: u64) -> IoResult<()> {
     fs_imp::utime(path, atime, mtime)
            .update_err("couldn't change_file_times", |e|
-               format!("{}; path={}", e, path.display()))
+               format!("{:?}; path={:?}", e, path.display()))
 }
 
 impl Reader for File {
     fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
         fn update_err<T>(result: IoResult<T>, file: &File) -> IoResult<T> {
             result.update_err("couldn't read file",
-                              |e| format!("{}; path={}",
+                              |e| format!("{:?}; path={:?}",
                                           e, file.path.display()))
         }
 
@@ -722,7 +722,7 @@ impl Writer for File {
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
         self.fd.write(buf)
             .update_err("couldn't write to file",
-                        |e| format!("{}; path={}", e, self.path.display()))
+                        |e| format!("{:?}; path={:?}", e, self.path.display()))
     }
 }
 
@@ -730,7 +730,7 @@ impl Seek for File {
     fn tell(&self) -> IoResult<u64> {
         self.fd.tell()
             .update_err("couldn't retrieve file cursor (`tell`)",
-                        |e| format!("{}; path={}", e, self.path.display()))
+                        |e| format!("{:?}; path={:?}", e, self.path.display()))
     }
 
     fn seek(&mut self, pos: i64, style: SeekStyle) -> IoResult<()> {
@@ -743,7 +743,7 @@ impl Seek for File {
             Err(e) => Err(e),
         };
         err.update_err("couldn't seek in file",
-                       |e| format!("{}; path={}", e, self.path.display()))
+                       |e| format!("{:?}; path={:?}", e, self.path.display()))
     }
 }
 
@@ -832,15 +832,15 @@ mod test {
     macro_rules! check { ($e:expr) => (
         match $e {
             Ok(t) => t,
-            Err(e) => panic!("{} failed with: {}", stringify!($e), e),
+            Err(e) => panic!("{} failed with: {:?}", stringify!($e), e),
         }
     ) }
 
     macro_rules! error { ($e:expr, $s:expr) => (
         match $e {
-            Ok(_) => panic!("Unexpected success. Should've been: {}", $s),
+            Ok(_) => panic!("Unexpected success. Should've been: {:?}", $s),
             Err(ref err) => assert!(err.to_string().contains($s.as_slice()),
-                                    format!("`{}` did not contain `{}`", err, $s))
+                                    format!("`{:?}` did not contain `{:?}`", err, $s))
         }
     ) }
 
@@ -906,7 +906,7 @@ mod test {
         if cfg!(unix) {
             error!(result, "no such file or directory");
         }
-        error!(result, format!("path={}; mode=open; access=read", filename.display()));
+        error!(result, format!("path={:?}; mode=open; access=read", filename.display()));
     }
 
     #[test]
@@ -920,7 +920,7 @@ mod test {
         if cfg!(unix) {
             error!(result, "no such file or directory");
         }
-        error!(result, format!("path={}", filename.display()));
+        error!(result, format!("path={:?}", filename.display()));
     }
 
     #[test]
@@ -1188,7 +1188,7 @@ mod test {
         error!(result, "couldn't recursively mkdir");
         error!(result, "couldn't create directory");
         error!(result, "mode=0700");
-        error!(result, format!("path={}", file.display()));
+        error!(result, format!("path={:?}", file.display()));
     }
 
     #[test]
@@ -1255,7 +1255,7 @@ mod test {
 
         error!(copy(&from, &to),
             format!("couldn't copy path (the source path is not an \
-                    existing file; from={}; to={})",
+                    existing file; from={:?}; to={:?})",
                     from.display(), to.display()));
 
         match copy(&from, &to) {
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 465c4f9c5c7..010cb814732 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -302,7 +302,7 @@ pub type IoResult<T> = Result<T, IoError>;
 /// # FIXME
 ///
 /// Is something like this sufficient? It's kind of archaic
-#[derive(PartialEq, Eq, Clone)]
+#[derive(PartialEq, Eq, Clone, Show)]
 pub struct IoError {
     /// An enumeration which can be matched against for determining the flavor
     /// of error.
@@ -339,7 +339,7 @@ impl IoError {
     }
 }
 
-impl fmt::Show for IoError {
+impl fmt::String for IoError {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             IoError { kind: OtherIoError, desc: "unknown error", detail: Some(ref detail) } =>
@@ -1656,7 +1656,7 @@ pub fn standard_error(kind: IoErrorKind) -> IoError {
 /// A mode specifies how a file should be opened or created. These modes are
 /// passed to `File::open_mode` and are used to control where the file is
 /// positioned when it is initially opened.
-#[derive(Copy, Clone, PartialEq, Eq)]
+#[derive(Copy, Clone, PartialEq, Eq, Show)]
 pub enum FileMode {
     /// Opens a file positioned at the beginning.
     Open,
@@ -1668,7 +1668,7 @@ pub enum FileMode {
 
 /// Access permissions with which the file should be opened. `File`s
 /// opened with `Read` will return an error if written to.
-#[derive(Copy, Clone, PartialEq, Eq)]
+#[derive(Copy, Clone, PartialEq, Eq, Show)]
 pub enum FileAccess {
     /// Read-only access, requests to write will result in an error
     Read,
@@ -1826,6 +1826,12 @@ impl Default for FilePermission {
 
 impl fmt::Show for FilePermission {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt(self, f)
+    }
+}
+
+impl fmt::String for FilePermission {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "{:04o}", self.bits)
     }
 }
diff --git a/src/libstd/io/net/addrinfo.rs b/src/libstd/io/net/addrinfo.rs
index 24d45dcd652..7825a4e16e1 100644
--- a/src/libstd/io/net/addrinfo.rs
+++ b/src/libstd/io/net/addrinfo.rs
@@ -29,7 +29,7 @@ use sys;
 use vec::Vec;
 
 /// Hints to the types of sockets that are desired when looking up hosts
-#[derive(Copy)]
+#[derive(Copy, Show)]
 pub enum SocketType {
     Stream, Datagram, Raw
 }
@@ -38,7 +38,7 @@ pub enum SocketType {
 /// to manipulate how a query is performed.
 ///
 /// The meaning of each of these flags can be found with `man -s 3 getaddrinfo`
-#[derive(Copy)]
+#[derive(Copy, Show)]
 pub enum Flag {
     AddrConfig,
     All,
@@ -51,7 +51,7 @@ pub enum Flag {
 
 /// A transport protocol associated with either a hint or a return value of
 /// `lookup`
-#[derive(Copy)]
+#[derive(Copy, Show)]
 pub enum Protocol {
     TCP, UDP
 }
@@ -61,7 +61,7 @@ pub enum Protocol {
 ///
 /// For details on these fields, see their corresponding definitions via
 /// `man -s 3 getaddrinfo`
-#[derive(Copy)]
+#[derive(Copy, Show)]
 pub struct Hint {
     pub family: uint,
     pub socktype: Option<SocketType>,
@@ -69,7 +69,7 @@ pub struct Hint {
     pub flags: uint,
 }
 
-#[derive(Copy)]
+#[derive(Copy, Show)]
 pub struct Info {
     pub address: SocketAddr,
     pub family: uint,
diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs
index 6cb2463fcbc..b9f653f86c2 100644
--- a/src/libstd/io/net/ip.rs
+++ b/src/libstd/io/net/ip.rs
@@ -32,13 +32,13 @@ use vec::Vec;
 
 pub type Port = u16;
 
-#[derive(Copy, PartialEq, Eq, Clone, Hash)]
+#[derive(Copy, PartialEq, Eq, Clone, Hash, Show)]
 pub enum IpAddr {
     Ipv4Addr(u8, u8, u8, u8),
     Ipv6Addr(u16, u16, u16, u16, u16, u16, u16, u16)
 }
 
-impl fmt::Show for IpAddr {
+impl fmt::String for IpAddr {
     fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             Ipv4Addr(a, b, c, d) =>
@@ -63,13 +63,13 @@ impl fmt::Show for IpAddr {
     }
 }
 
-#[derive(Copy, PartialEq, Eq, Clone, Hash)]
+#[derive(Copy, PartialEq, Eq, Clone, Hash, Show)]
 pub struct SocketAddr {
     pub ip: IpAddr,
     pub port: Port,
 }
 
-impl fmt::Show for SocketAddr {
+impl fmt::String for SocketAddr {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self.ip {
             Ipv4Addr(..) => write!(f, "{}:{}", self.ip, self.port),
diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs
index 5f77ab38d74..efb57341620 100644
--- a/src/libstd/io/process.rs
+++ b/src/libstd/io/process.rs
@@ -395,7 +395,14 @@ impl Command {
     }
 }
 
+#[cfg(stage0)]
 impl fmt::Show for Command {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt(self, f)
+    }
+}
+
+impl fmt::String for Command {
     /// Format the program and arguments of a Command for display. Any
     /// non-utf8 data is lossily converted using the utf8 replacement
     /// character.
@@ -506,6 +513,14 @@ pub enum ProcessExit {
 impl fmt::Show for ProcessExit {
     /// Format a ProcessExit enum, to nicely present the information.
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt(self, f)
+    }
+}
+
+
+impl fmt::String for ProcessExit {
+    /// Format a ProcessExit enum, to nicely present the information.
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
             ExitStatus(code) =>  write!(f, "exit code: {}", code),
             ExitSignal(code) =>  write!(f, "signal: {}", code),
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index f571bed3ba2..d7bc572106e 100644
--- a/src/libstd/io/stdio.rs
+++ b/src/libstd/io/stdio.rs
@@ -349,7 +349,7 @@ fn with_task_stdout<F>(f: F) where F: FnOnce(&mut Writer) -> IoResult<()> {
     });
     match result {
         Ok(()) => {}
-        Err(e) => panic!("failed printing to stdout: {}", e),
+        Err(e) => panic!("failed printing to stdout: {:?}", e),
     }
 }