Skip to content

Commit 6b3916e

Browse files
committed
---
yaml --- r: 93039 b: refs/heads/auto c: 95ace50 h: refs/heads/master i: 93037: 1946b7a 93035: 7ccb32d 93031: 82b1de4 93023: 2b40b59 v: v3
1 parent 9963f99 commit 6b3916e

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: ba801577b909cf1123846bb425d5f489db8325b8
16+
refs/heads/auto: 95ace50643218f97849a8073bb201583f9639fdb
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/libstd/io/mod.rs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -186,23 +186,29 @@ while still providing feedback about errors. The basic strategy:
186186
so that nullable values do not have to be 'unwrapped' before use.
187187
188188
These features combine in the API to allow for expressions like
189-
`File::new("diary.txt").write_line("met a girl")` without having to
190-
worry about whether "diary.txt" exists or whether the write
191-
succeeds. As written, if either `new` or `write_line` encounters
192-
an error the task will fail.
193-
194-
If you wanted to handle the error though you might write
195-
196-
let mut error = None;
197-
do io_error::cond(|e: IoError| {
198-
error = Some(e);
199-
}).in {
200-
File::new("diary.txt").write_line("met a girl");
201-
}
202-
203-
if error.is_some() {
204-
println("failed to write my diary");
205-
}
189+
`File::create(&Path::new("diary.txt")).write(bytes!("Met a girl.\n"))`
190+
without having to worry about whether "diary.txt" exists or whether
191+
the write succeeds. As written, if either `new` or `write_line`
192+
encounters an error the task will fail.
193+
194+
If you wanted to handle the error though you might write:
195+
196+
```rust
197+
use std::io::File;
198+
use std::io::{IoError, io_error};
199+
200+
let mut error = None;
201+
io_error::cond.trap(|e: IoError| {
202+
error = Some(e);
203+
}).inside(|| {
204+
File::create(&Path::new("diary.txt")).write(bytes!("Met a girl.\n"));
205+
});
206+
207+
if error.is_some() {
208+
println("failed to write my diary");
209+
}
210+
# ::std::io::fs::unlink(&Path::new("diary.txt"));
211+
```
206212
207213
XXX: Need better condition handling syntax
208214
@@ -498,10 +504,16 @@ pub trait Reader {
498504
///
499505
/// # Example
500506
///
501-
/// let mut reader = BufferedReader::new(File::open(&Path::new("foo.txt")));
502-
/// for line in reader.lines() {
503-
/// println(line);
504-
/// }
507+
/// ```rust
508+
/// use std::io;
509+
/// # let _g = ::std::io::ignore_io_error();
510+
/// let mut reader = io::stdin();
511+
///
512+
/// let mut bytes = [0, .. 10];
513+
/// reader.read(bytes);
514+
///
515+
/// if reader.eof() { println("stdin() had at most 10 bytes of data."); }
516+
/// ```
505517
///
506518
/// # Failure
507519
///
@@ -1057,6 +1069,18 @@ pub trait Buffer: Reader {
10571069
/// encoded unicode codepoints. If a newline is encountered, then the
10581070
/// newline is contained in the returned string.
10591071
///
1072+
/// # Example
1073+
///
1074+
/// ```rust
1075+
/// use std::io::buffered::BufferedReader;
1076+
/// use std::io;
1077+
/// # let _g = ::std::io::ignore_io_error();
1078+
///
1079+
/// let mut reader = BufferedReader::new(io::stdin());
1080+
///
1081+
/// let input = reader.read_line().unwrap_or(~"nothing");
1082+
/// ```
1083+
///
10601084
/// # Failure
10611085
///
10621086
/// This function will raise on the `io_error` condition (except for

0 commit comments

Comments
 (0)