Skip to content

Commit 84ebf74

Browse files
committed
auto merge of #12607 : alexcrichton/rust/io++, r=brson
This lowers the #[allow(missing_doc)] directive into some of the lower modules which are less mature. Most I/O modules now require comprehensive documentation.
2 parents 58ea029 + 311ac8f commit 84ebf74

File tree

13 files changed

+188
-33
lines changed

13 files changed

+188
-33
lines changed

src/libstd/io/comm_adapters.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct PortReader {
4242
}
4343

4444
impl PortReader {
45+
/// Wraps a `Port` in a `PortReader` structure
4546
pub fn new(port: Port<~[u8]>) -> PortReader {
4647
PortReader {
4748
buf: None,
@@ -96,10 +97,11 @@ impl Reader for PortReader {
9697
/// writer.write("hello, world".as_bytes());
9798
/// ```
9899
pub struct ChanWriter {
99-
chan: Chan<~[u8]>,
100+
priv chan: Chan<~[u8]>,
100101
}
101102

102103
impl ChanWriter {
104+
/// Wraps a channel in a `ChanWriter` structure
103105
pub fn new(chan: Chan<~[u8]>) -> ChanWriter {
104106
ChanWriter { chan: chan }
105107
}

src/libstd/io/extensions.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Utility mixins that apply to all Readers and Writers
1212
13+
#[allow(missing_doc)];
14+
1315
// FIXME: Not sure how this should be structured
1416
// FIXME: Iteration should probably be considered separately
1517

src/libstd/io/mem.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ pub struct BufWriter<'a> {
224224
}
225225

226226
impl<'a> BufWriter<'a> {
227+
/// Creates a new `BufWriter` which will wrap the specified buffer. The
228+
/// writer initially starts at position 0.
227229
pub fn new<'a>(buf: &'a mut [u8]) -> BufWriter<'a> {
228230
BufWriter {
229231
buf: buf,

src/libstd/io/mod.rs

Lines changed: 126 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ will also return an error.
174174
175175
*/
176176

177-
#[allow(missing_doc)];
178177
#[deny(unused_must_use)];
179178

180179
use cast;
@@ -247,6 +246,7 @@ mod comm_adapters;
247246
// https://groups.google.com/forum/#!topic/libuv/oQO1HJAIDdA
248247
static DEFAULT_BUF_SIZE: uint = 1024 * 64;
249248

249+
/// A convenient typedef of the return value of any I/O action.
250250
pub 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)]
258258
pub 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)]
275280
pub 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.
295307
pub 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+
/// ```
658694
pub 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

662699
impl<'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.
671718
pub 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+
/// ```
866937
pub 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.
876950
pub trait Stream: Reader + Writer { }
877951

878952
impl<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.
10851162
pub 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.
10941174
pub 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+
/// ```
11601251
pub 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.
11961279
pub 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)]
12041290
pub 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+
/// ```
12131327
pub 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)]
12531368
pub struct UnstableFileStat {
12541369
device: u64,
12551370
inode: u64,

src/libstd/io/net/addrinfo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ getaddrinfo()
1717
1818
*/
1919

20+
#[allow(missing_doc)];
21+
2022
use io::IoResult;
2123
use io::net::ip::{SocketAddr, IpAddr};
2224
use option::{Option, Some, None};

src/libstd/io/net/ip.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[allow(missing_doc)];
12+
1113
use container::Container;
1214
use fmt;
1315
use from_str::FromStr;

src/libstd/io/net/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! Networking I/O
12+
1113
pub use self::addrinfo::get_host_addresses;
1214

1315
pub mod addrinfo;

src/libstd/io/net/udp.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[allow(missing_doc)];
12+
1113
use clone::Clone;
1214
use result::{Ok, Err};
1315
use io::net::ip::SocketAddr;

src/libstd/io/net/unix.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ instances as clients.
2222
2323
*/
2424

25+
#[allow(missing_doc)];
26+
2527
use prelude::*;
2628

2729
use c_str::ToCStr;

src/libstd/io/pipe.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
//! Currently these aren't particularly useful, there only exists bindings
1414
//! enough so that pipes can be created to child processes.
1515
16+
#[allow(missing_doc)];
17+
1618
use prelude::*;
1719
use io::IoResult;
1820
use libc;
@@ -46,6 +48,7 @@ impl PipeStream {
4648
})
4749
}
4850

51+
#[doc(hidden)]
4952
pub fn new(inner: ~RtioPipe) -> PipeStream {
5053
PipeStream { obj: inner }
5154
}

src/libstd/io/signal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use result::{Ok, Err};
2929
use rt::rtio::{IoFactory, LocalIo, RtioSignal};
3030
use vec::{ImmutableVector, OwnedVector};
3131

32+
/// Signals that can be sent and received
3233
#[repr(int)]
3334
#[deriving(Eq, Hash)]
3435
pub enum Signum {

src/libstd/io/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ fn base_port() -> u16 {
121121
return final_base;
122122
}
123123

124+
/// Raises the file descriptor limit when running tests if necessary
124125
pub fn raise_fd_limit() {
125126
unsafe { darwin_fd_limit::raise_fd_limit() }
126127
}

0 commit comments

Comments
 (0)