]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/io/mod.rs
rollup merge of #17355 : gamazeps/issue17210
[rust.git] / src / libstd / io / mod.rs
index 905012b7bf33abf1ec4024bba353d81f0e83888f..ff508c802d8455cc36209048bba9abdd4e27a615 100644 (file)
@@ -578,7 +578,7 @@ fn read_at_least(&mut self, min: uint, buf: &mut [u8]) -> IoResult<uint> {
         while read < min {
             let mut zeroes = 0;
             loop {
-                match self.read(buf.mut_slice_from(read)) {
+                match self.read(buf.slice_from_mut(read)) {
                     Ok(0) => {
                         zeroes += 1;
                         if zeroes >= NO_PROGRESS_LIMIT {
@@ -945,7 +945,7 @@ fn by_ref<'a>(&'a mut self) -> RefReader<'a, Self> {
     }
 }
 
-impl Reader for Box<Reader+'static> {
+impl<'a> Reader for Box<Reader+'a> {
     fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.read(buf) }
 }
 
@@ -1279,7 +1279,7 @@ fn by_ref<'a>(&'a mut self) -> RefWriter<'a, Self> {
     }
 }
 
-impl Writer for Box<Writer+'static> {
+impl<'a> Writer for Box<Writer+'a> {
     #[inline]
     fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write(buf) }
 
@@ -1418,7 +1418,7 @@ pub trait Buffer: Reader {
     fn consume(&mut self, amt: uint);
 
     /// Reads the next line of input, interpreted as a sequence of UTF-8
-    /// encoded unicode codepoints. If a newline is encountered, then the
+    /// encoded Unicode codepoints. If a newline is encountered, then the
     /// newline is contained in the returned string.
     ///
     /// # Example
@@ -1524,7 +1524,7 @@ fn read_char(&mut self) -> IoResult<char> {
         {
             let mut start = 1;
             while start < width {
-                match try!(self.read(buf.mut_slice(start, width))) {
+                match try!(self.read(buf.slice_mut(start, width))) {
                     n if n == width - start => break,
                     n if n < width - start => { start += n; }
                     _ => return Err(standard_error(InvalidInput)),
@@ -1721,6 +1721,7 @@ pub enum FileType {
 /// # Example
 ///
 /// ```
+/// # use std::io::fs::PathExtensions;
 /// # fn main() {}
 /// # fn foo() {
 /// let info = match Path::new("foo.txt").stat() {
@@ -1794,10 +1795,9 @@ pub struct UnstableFileStat {
     pub gen: u64,
 }
 
-bitflags!(
-    #[doc="A set of permissions for a file or directory is represented
-by a set of flags which are or'd together."]
-    #[deriving(Show)]
+bitflags! {
+    #[doc = "A set of permissions for a file or directory is represented"]
+    #[doc = "by a set of flags which are or'd together."]
     flags FilePermission: u32 {
         static UserRead     = 0o400,
         static UserWrite    = 0o200,
@@ -1813,29 +1813,37 @@ pub struct UnstableFileStat {
         static GroupRWX = GroupRead.bits | GroupWrite.bits | GroupExecute.bits,
         static OtherRWX = OtherRead.bits | OtherWrite.bits | OtherExecute.bits,
 
-        #[doc="Permissions for user owned files, equivalent to 0644 on
-unix-like systems."]
+        #[doc = "Permissions for user owned files, equivalent to 0644 on"]
+        #[doc = "unix-like systems."]
         static UserFile = UserRead.bits | UserWrite.bits | GroupRead.bits | OtherRead.bits,
 
-        #[doc="Permissions for user owned directories, equivalent to 0755 on
-unix-like systems."]
+        #[doc = "Permissions for user owned directories, equivalent to 0755 on"]
+        #[doc = "unix-like systems."]
         static UserDir  = UserRWX.bits | GroupRead.bits | GroupExecute.bits |
                    OtherRead.bits | OtherExecute.bits,
 
-        #[doc="Permissions for user owned executables, equivalent to 0755
-on unix-like systems."]
+        #[doc = "Permissions for user owned executables, equivalent to 0755"]
+        #[doc = "on unix-like systems."]
         static UserExec = UserDir.bits,
 
-        #[doc="All possible permissions enabled."]
-        static AllPermissions = UserRWX.bits | GroupRWX.bits | OtherRWX.bits
+        #[doc = "All possible permissions enabled."]
+        static AllPermissions = UserRWX.bits | GroupRWX.bits | OtherRWX.bits,
     }
-)
+}
 
 impl Default for FilePermission {
     #[inline]
     fn default() -> FilePermission { FilePermission::empty() }
 }
 
+impl fmt::Show for FilePermission {
+    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+        formatter.fill = '0';
+        formatter.width = Some(4);
+        (&self.bits as &fmt::Octal).fmt(formatter)
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::{IoResult, Reader, MemReader, NoProgress, InvalidInput};
@@ -1937,4 +1945,18 @@ fn test_push_at_least() {
         let mut r = MemReader::new(Vec::from_slice(b"hello, world!"));
         assert_eq!(r.push_at_least(5, 1, &mut buf).unwrap_err().kind, InvalidInput);
     }
+
+    #[test]
+    fn test_show() {
+        use super::*;
+
+        assert_eq!(format!("{}", UserRead), "0400".to_string());
+        assert_eq!(format!("{}", UserFile), "0644".to_string());
+        assert_eq!(format!("{}", UserExec), "0755".to_string());
+        assert_eq!(format!("{}", UserRWX),  "0700".to_string());
+        assert_eq!(format!("{}", GroupRWX), "0070".to_string());
+        assert_eq!(format!("{}", OtherRWX), "0007".to_string());
+        assert_eq!(format!("{}", AllPermissions), "0777".to_string());
+        assert_eq!(format!("{}", UserRead | UserWrite | OtherWrite), "0602".to_string());
+    }
 }