diff options
| author | bors <bors@rust-lang.org> | 2013-04-02 22:24:41 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-04-02 22:24:41 -0700 |
| commit | 0cc903015b395c0d9eada3fe3376f2447cc835b6 (patch) | |
| tree | 9c4f4a2d1f9aaed428f73da8cdd456a50ca1eb0c /src/rt/sync/rust_thread.cpp | |
| parent | 26d8b5188a248a597c9c0b70242ce85e02ccf652 (diff) | |
| parent | fea1380a9a0ca94738132db4d51ec4bd86bac3dd (diff) | |
| download | rust-0cc903015b395c0d9eada3fe3376f2447cc835b6.tar.gz rust-0cc903015b395c0d9eada3fe3376f2447cc835b6.zip | |
auto merge of #5202 : dbaupp/rust/std-fileinput, r=graydon
As per https://github.com/mozilla/rust/wiki/Note-wanted-libraries.
Iterates over lines in a series of files, e.g. a basic `cat`
```rust
use std::fileinput;
fn main() {
for fileinput::input |line| {
io::println(line);
}
}
```
The API is essentially a subset of [Python's fileinput module](http://docs.python.org/3.3/library/fileinput.html), although the lack of default arguments and global mutable state means that there are extra functions to handle a few different cases (files from command line arguments, files from a vector, accessing current filename/line number).
A few points that possibly require adjustment:
- Most functions take vectors of `Path` (well, `Option<Path>`) rather than just `~str`, since this seems safer, and allows finer control without the number of different functions/methods increasing exponentially.
- `pathify` has a stupid name.
- I'm not quite sure how to mock tests that require external files: the tests in `libcore/io.rs` seem to indicate using a `tmp` subdirectory, so that's what I did, but I can't reliably build rust on this computer to test (sorry! although I have run the tests in just `fileinput.rs` after creating `./tmp/` manually).
- The documentation I've written seems pretty crappy and not particularly clear.
- Only UTF8 files are supported.
Diffstat (limited to 'src/rt/sync/rust_thread.cpp')
0 files changed, 0 insertions, 0 deletions
