@@ -174,7 +174,6 @@ will also return an error.
174174
175175*/
176176
177- #[ allow( missing_doc) ] ;
178177#[ deny( unused_must_use) ] ;
179178
180179use cast;
@@ -247,6 +246,7 @@ mod comm_adapters;
247246// https://groups.google.com/forum/#!topic/libuv/oQO1HJAIDdA
248247static DEFAULT_BUF_SIZE : uint = 1024 * 64 ;
249248
249+ /// A convenient typedef of the return value of any I/O action.
250250pub type IoResult < T > = Result < T , IoError > ;
251251
252252/// The type passed to I/O condition handlers to indicate error
@@ -256,8 +256,12 @@ pub type IoResult<T> = Result<T, IoError>;
256256/// Is something like this sufficient? It's kind of archaic
257257#[ deriving( Eq , Clone ) ]
258258pub struct IoError {
259+ /// An enumeration which can be matched against for determining the flavor
260+ /// of error.
259261 kind : IoErrorKind ,
262+ /// A human-readable description about the error
260263 desc : & ' static str ,
264+ /// Detailed information about this error, not always available
261265 detail : Option < ~str >
262266}
263267
@@ -272,6 +276,7 @@ impl fmt::Show for IoError {
272276}
273277
274278#[ deriving( Eq , Clone , Show ) ]
279+ #[ allow( missing_doc) ]
275280pub enum IoErrorKind {
276281 OtherIoError ,
277282 EndOfFile ,
@@ -292,6 +297,13 @@ pub enum IoErrorKind {
292297 InvalidInput ,
293298}
294299
300+ /// A trait for objects which are byte-oriented streams. Readers are defined by
301+ /// one method, `read`. This function will block until data is available,
302+ /// filling in the provided buffer with any data read.
303+ ///
304+ /// Readers are intended to be composable with one another. Many objects
305+ /// throughout the I/O and related libraries take and provide types which
306+ /// implement the `Reader` trait.
295307pub trait Reader {
296308
297309 // Only method which need to get implemented for this trait
@@ -655,8 +667,33 @@ impl<'a> Reader for &'a mut Reader {
655667 fn read ( & mut self , buf : & mut [ u8 ] ) -> IoResult < uint > { self . read ( buf) }
656668}
657669
670+ /// A `RefReader` is a struct implementing `Reader` which contains a reference
671+ /// to another reader. This is often useful when composing streams.
672+ ///
673+ /// # Example
674+ ///
675+ /// ```
676+ /// # fn main() {}
677+ /// # fn process_input<R: Reader>(r: R) {}
678+ /// # fn foo() {
679+ /// use std::io;
680+ /// use std::io::util::LimitReader;
681+ ///
682+ /// let mut stream = io::stdin();
683+ ///
684+ /// // Only allow the function to process at most one kilobyte of input
685+ /// {
686+ /// let stream = LimitReader::new(stream.by_ref(), 1024);
687+ /// process_input(stream);
688+ /// }
689+ ///
690+ /// // 'stream' is still available for use here
691+ ///
692+ /// # }
693+ /// ```
658694pub struct RefReader < ' a , R > {
659- priv inner : & ' a mut R
695+ /// The underlying reader which this is referencing
696+ inner : & ' a mut R
660697}
661698
662699impl < ' a , R : Reader > Reader for RefReader < ' a , R > {
@@ -668,6 +705,16 @@ fn extend_sign(val: u64, nbytes: uint) -> i64 {
668705 ( val << shift) as i64 >> shift
669706}
670707
708+ /// A trait for objects which are byte-oriented streams. Writers are defined by
709+ /// one method, `write`. This function will block until the provided buffer of
710+ /// bytes has been entirely written, and it will return any failurs which occur.
711+ ///
712+ /// Another commonly overriden method is the `flush` method for writers such as
713+ /// buffered writers.
714+ ///
715+ /// Writers are intended to be composable with one another. Many objects
716+ /// throughout the I/O and related libraries take and provide types which
717+ /// implement the `Writer` trait.
671718pub trait Writer {
672719 /// Write the entirety of a given buffer
673720 ///
@@ -863,7 +910,32 @@ impl<'a> Writer for &'a mut Writer {
863910 fn flush ( & mut self ) -> IoResult < ( ) > { self . flush ( ) }
864911}
865912
913+ /// A `RefWriter` is a struct implementing `Writer` which contains a reference
914+ /// to another writer. This is often useful when composing streams.
915+ ///
916+ /// # Example
917+ ///
918+ /// ```
919+ /// # fn main() {}
920+ /// # fn process_input<R: Reader>(r: R) {}
921+ /// # fn foo () {
922+ /// use std::io::util::TeeReader;
923+ /// use std::io::{stdin, MemWriter};
924+ ///
925+ /// let mut output = MemWriter::new();
926+ ///
927+ /// {
928+ /// // Don't give ownership of 'output' to the 'tee'. Instead we keep a
929+ /// // handle to it in the outer scope
930+ /// let mut tee = TeeReader::new(stdin(), output.by_ref());
931+ /// process_input(tee);
932+ /// }
933+ ///
934+ /// println!("input processed: {}", output.unwrap());
935+ /// # }
936+ /// ```
866937pub struct RefWriter < ' a , W > {
938+ /// The underlying writer which this is referencing
867939 inner : & ' a mut W
868940}
869941
@@ -873,6 +945,8 @@ impl<'a, W: Writer> Writer for RefWriter<'a, W> {
873945}
874946
875947
948+ /// A Stream is a readable and a writable object. Data written is typically
949+ /// received by the object which reads receive data from.
876950pub trait Stream : Reader + Writer { }
877951
878952impl < T : Reader + Writer > Stream for T { }
@@ -1070,7 +1144,8 @@ pub trait Buffer: Reader {
10701144 }
10711145 }
10721146
1073- /// Create an iterator that reads a utf8-encoded character on each iteration until EOF.
1147+ /// Create an iterator that reads a utf8-encoded character on each iteration
1148+ /// until EOF.
10741149 ///
10751150 /// # Error
10761151 ///
@@ -1082,6 +1157,8 @@ pub trait Buffer: Reader {
10821157 }
10831158}
10841159
1160+ /// When seeking, the resulting cursor is offset from a base by the offset given
1161+ /// to the `seek` function. The base used is specified by this enumeration.
10851162pub enum SeekStyle {
10861163 /// Seek from the beginning of the stream
10871164 SeekSet ,
@@ -1091,6 +1168,9 @@ pub enum SeekStyle {
10911168 SeekCur ,
10921169}
10931170
1171+ /// An object implementing `Seek` internally has some form of cursor which can
1172+ /// be moved within a stream of bytes. The stream typically has a fixed size,
1173+ /// allowing seeking relative to either end.
10941174pub trait Seek {
10951175 /// Return position of file cursor in the stream
10961176 fn tell ( & self ) -> IoResult < u64 > ;
@@ -1157,6 +1237,17 @@ impl<'a, T, A: Acceptor<T>> Iterator<IoResult<T>> for IncomingConnections<'a, A>
11571237 }
11581238}
11591239
1240+ /// Creates a standard error for a commonly used flavor of error. The `detail`
1241+ /// field of the returned error will always be `None`.
1242+ ///
1243+ /// # Example
1244+ ///
1245+ /// ```
1246+ /// use std::io;
1247+ ///
1248+ /// let eof = io::standard_error(io::EndOfFile);
1249+ /// let einval = io::standard_error(io::InvalidInput);
1250+ /// ```
11601251pub fn standard_error ( kind : IoErrorKind ) -> IoError {
11611252 let desc = match kind {
11621253 EndOfFile => "end of file" ,
@@ -1171,14 +1262,6 @@ pub fn standard_error(kind: IoErrorKind) -> IoError {
11711262 }
11721263}
11731264
1174- pub fn placeholder_error ( ) -> IoError {
1175- IoError {
1176- kind : OtherIoError ,
1177- desc : "Placeholder error. You shouldn't be seeing this" ,
1178- detail : None
1179- }
1180- }
1181-
11821265/// A mode specifies how a file should be opened or created. These modes are
11831266/// passed to `File::open_mode` and are used to control where the file is
11841267/// positioned when it is initially opened.
@@ -1194,22 +1277,53 @@ pub enum FileMode {
11941277/// Access permissions with which the file should be opened. `File`s
11951278/// opened with `Read` will return an error if written to.
11961279pub enum FileAccess {
1280+ /// Read-only access, requests to write will result in an error
11971281 Read ,
1282+ /// Write-only access, requests to read will result in an error
11981283 Write ,
1284+ /// Read-write access, no requests are denied by default
11991285 ReadWrite ,
12001286}
12011287
12021288/// Different kinds of files which can be identified by a call to stat
12031289#[ deriving( Eq ) ]
12041290pub enum FileType {
1291+ /// This is a normal file, corresponding to `S_IFREG`
12051292 TypeFile ,
1293+
1294+ /// This file is a directory, corresponding to `S_IFDIR`
12061295 TypeDirectory ,
1296+
1297+ /// This file is a named pipe, corresponding to `S_IFIFO`
12071298 TypeNamedPipe ,
1299+
1300+ /// This file is a block device, corresponding to `S_IFBLK`
12081301 TypeBlockSpecial ,
1302+
1303+ /// This file is a symbolic link to another file, corresponding to `S_IFLNK`
12091304 TypeSymlink ,
1305+
1306+ /// The type of this file is not recognized as one of the other categories
12101307 TypeUnknown ,
12111308}
12121309
1310+ /// A structure used to describe metadata information about a file. This
1311+ /// structure is created through the `stat` method on a `Path`.
1312+ ///
1313+ /// # Example
1314+ ///
1315+ /// ```
1316+ /// # fn main() {}
1317+ /// # fn foo() {
1318+ /// let info = match Path::new("foo.txt").stat() {
1319+ /// Ok(stat) => stat,
1320+ /// Err(e) => fail!("couldn't read foo.txt: {}", e),
1321+ /// };
1322+ ///
1323+ /// println!("path: {}", info.path.display());
1324+ /// println!("byte size: {}", info.size);
1325+ /// # }
1326+ /// ```
12131327pub struct FileStat {
12141328 /// The path that this stat structure is describing
12151329 path : Path ,
@@ -1250,6 +1364,7 @@ pub struct FileStat {
12501364/// structure. This information is not necessarily platform independent, and may
12511365/// have different meanings or no meaning at all on some platforms.
12521366#[ unstable]
1367+ #[ allow( missing_doc) ]
12531368pub struct UnstableFileStat {
12541369 device : u64 ,
12551370 inode : u64 ,
0 commit comments