@@ -174,7 +174,6 @@ will also return an error.
174
174
175
175
*/
176
176
177
- #[ allow( missing_doc) ] ;
178
177
#[ deny( unused_must_use) ] ;
179
178
180
179
use cast;
@@ -247,6 +246,7 @@ mod comm_adapters;
247
246
// https://groups.google.com/forum/#!topic/libuv/oQO1HJAIDdA
248
247
static DEFAULT_BUF_SIZE : uint = 1024 * 64 ;
249
248
249
+ /// A convenient typedef of the return value of any I/O action.
250
250
pub type IoResult < T > = Result < T , IoError > ;
251
251
252
252
/// The type passed to I/O condition handlers to indicate error
@@ -256,8 +256,12 @@ pub type IoResult<T> = Result<T, IoError>;
256
256
/// Is something like this sufficient? It's kind of archaic
257
257
#[ deriving( Eq , Clone ) ]
258
258
pub struct IoError {
259
+ /// An enumeration which can be matched against for determining the flavor
260
+ /// of error.
259
261
kind : IoErrorKind ,
262
+ /// A human-readable description about the error
260
263
desc : & ' static str ,
264
+ /// Detailed information about this error, not always available
261
265
detail : Option < ~str >
262
266
}
263
267
@@ -272,6 +276,7 @@ impl fmt::Show for IoError {
272
276
}
273
277
274
278
#[ deriving( Eq , Clone , Show ) ]
279
+ #[ allow( missing_doc) ]
275
280
pub enum IoErrorKind {
276
281
OtherIoError ,
277
282
EndOfFile ,
@@ -292,6 +297,13 @@ pub enum IoErrorKind {
292
297
InvalidInput ,
293
298
}
294
299
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.
295
307
pub trait Reader {
296
308
297
309
// Only method which need to get implemented for this trait
@@ -655,8 +667,33 @@ impl<'a> Reader for &'a mut Reader {
655
667
fn read ( & mut self , buf : & mut [ u8 ] ) -> IoResult < uint > { self . read ( buf) }
656
668
}
657
669
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
+ /// ```
658
694
pub struct RefReader < ' a , R > {
659
- priv inner : & ' a mut R
695
+ /// The underlying reader which this is referencing
696
+ inner : & ' a mut R
660
697
}
661
698
662
699
impl < ' a , R : Reader > Reader for RefReader < ' a , R > {
@@ -668,6 +705,16 @@ fn extend_sign(val: u64, nbytes: uint) -> i64 {
668
705
( val << shift) as i64 >> shift
669
706
}
670
707
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.
671
718
pub trait Writer {
672
719
/// Write the entirety of a given buffer
673
720
///
@@ -863,7 +910,32 @@ impl<'a> Writer for &'a mut Writer {
863
910
fn flush ( & mut self ) -> IoResult < ( ) > { self . flush ( ) }
864
911
}
865
912
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
+ /// ```
866
937
pub struct RefWriter < ' a , W > {
938
+ /// The underlying writer which this is referencing
867
939
inner : & ' a mut W
868
940
}
869
941
@@ -873,6 +945,8 @@ impl<'a, W: Writer> Writer for RefWriter<'a, W> {
873
945
}
874
946
875
947
948
+ /// A Stream is a readable and a writable object. Data written is typically
949
+ /// received by the object which reads receive data from.
876
950
pub trait Stream : Reader + Writer { }
877
951
878
952
impl < T : Reader + Writer > Stream for T { }
@@ -1070,7 +1144,8 @@ pub trait Buffer: Reader {
1070
1144
}
1071
1145
}
1072
1146
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.
1074
1149
///
1075
1150
/// # Error
1076
1151
///
@@ -1082,6 +1157,8 @@ pub trait Buffer: Reader {
1082
1157
}
1083
1158
}
1084
1159
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.
1085
1162
pub enum SeekStyle {
1086
1163
/// Seek from the beginning of the stream
1087
1164
SeekSet ,
@@ -1091,6 +1168,9 @@ pub enum SeekStyle {
1091
1168
SeekCur ,
1092
1169
}
1093
1170
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.
1094
1174
pub trait Seek {
1095
1175
/// Return position of file cursor in the stream
1096
1176
fn tell ( & self ) -> IoResult < u64 > ;
@@ -1157,6 +1237,17 @@ impl<'a, T, A: Acceptor<T>> Iterator<IoResult<T>> for IncomingConnections<'a, A>
1157
1237
}
1158
1238
}
1159
1239
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
+ /// ```
1160
1251
pub fn standard_error ( kind : IoErrorKind ) -> IoError {
1161
1252
let desc = match kind {
1162
1253
EndOfFile => "end of file" ,
@@ -1171,14 +1262,6 @@ pub fn standard_error(kind: IoErrorKind) -> IoError {
1171
1262
}
1172
1263
}
1173
1264
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
-
1182
1265
/// A mode specifies how a file should be opened or created. These modes are
1183
1266
/// passed to `File::open_mode` and are used to control where the file is
1184
1267
/// positioned when it is initially opened.
@@ -1194,22 +1277,53 @@ pub enum FileMode {
1194
1277
/// Access permissions with which the file should be opened. `File`s
1195
1278
/// opened with `Read` will return an error if written to.
1196
1279
pub enum FileAccess {
1280
+ /// Read-only access, requests to write will result in an error
1197
1281
Read ,
1282
+ /// Write-only access, requests to read will result in an error
1198
1283
Write ,
1284
+ /// Read-write access, no requests are denied by default
1199
1285
ReadWrite ,
1200
1286
}
1201
1287
1202
1288
/// Different kinds of files which can be identified by a call to stat
1203
1289
#[ deriving( Eq ) ]
1204
1290
pub enum FileType {
1291
+ /// This is a normal file, corresponding to `S_IFREG`
1205
1292
TypeFile ,
1293
+
1294
+ /// This file is a directory, corresponding to `S_IFDIR`
1206
1295
TypeDirectory ,
1296
+
1297
+ /// This file is a named pipe, corresponding to `S_IFIFO`
1207
1298
TypeNamedPipe ,
1299
+
1300
+ /// This file is a block device, corresponding to `S_IFBLK`
1208
1301
TypeBlockSpecial ,
1302
+
1303
+ /// This file is a symbolic link to another file, corresponding to `S_IFLNK`
1209
1304
TypeSymlink ,
1305
+
1306
+ /// The type of this file is not recognized as one of the other categories
1210
1307
TypeUnknown ,
1211
1308
}
1212
1309
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
+ /// ```
1213
1327
pub struct FileStat {
1214
1328
/// The path that this stat structure is describing
1215
1329
path : Path ,
@@ -1250,6 +1364,7 @@ pub struct FileStat {
1250
1364
/// structure. This information is not necessarily platform independent, and may
1251
1365
/// have different meanings or no meaning at all on some platforms.
1252
1366
#[ unstable]
1367
+ #[ allow( missing_doc) ]
1253
1368
pub struct UnstableFileStat {
1254
1369
device : u64 ,
1255
1370
inode : u64 ,
0 commit comments