-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement fileinput #5202
Implement fileinput #5202
Conversation
@graydon I think I fixed the build failure. (Edit: I see you're already on top of it.) |
Sorry :( (Last attempt before I give up and stop attempting to contribute while I can't test.) |
@graydon I've finally got a computer that compiles rust in less than 2 hours, and so I've sorted out all the problems with this patch. |
Great! I will approve it for landing, but I did actually start poking at it as promised, just ... I got side tracked and started fussing with the actual implementation. In particular I started trying to make improvements, but each one led to a more-general one:
Around that point I got sidetracked and didn't finish. Sorry. If you want to make any or all of those changes in followup patches I'd certainly appreciate it. Otherwise it'll just go on the "more refactoring to the io modules" pile-o-bugs. |
Sorry for stepping on your toes! Do you have the partial code in a branch somewhere that I could continue off? |
No worries. Unfortunately not, I kept deleting and restarting what I was doing. It wasn't terribly deep; the comment I wrote above is more informative than any of the half-sketch work I had done. |
Hm, some quick questions/comments.
Do you mean
I see two useful methods: a plain In summary: I can't see a good way of designing this that allows it to be reused for
I thought about doing this before, but discarded it without actually trying (not quite sure why), but it's clearly a better solution than renaming methods; although it likely comes a performance cost due to having to scan for |
I'm not sure why there'd be a performance cost to implementing Reader, can you elaborate? Yes on returning |
The performance cost is just having to scan everything for Hmm, ok, not sure why I didn't follow the convention with the (with slices) let mut lines = ~[];
for fileinput::input |slice : &str| {
lines.push(str::from_slice(slice))
} vs. (as it is now) let mut lines = ~[];
for fileinput::input |owned : ~str| {
lines.push(owned)
} (Similar reasoning could be used for many of the |
The underlying (In general, any time it seems like we're using (Also also: sorry for being picky on this and/or trying to use it as some kind of teachable moment. Your patch is good and any time you get frustrated with this conversation just say so and I'm happy to merge it in the state it's in. Any module doing something |
Ok, I understand about I'm not getting frustrated: it's not my project and I completely understand being picky and trying to get things as you would prefer, and anyway, I really appreciate that you (and the rest of the core team) are so willing to spend the time to help me get my contributions into shape. (And, the longer the conversation goes now, the more I'll learn about the design decisions etc, so (hopefully) the shorter it'll be next time.) |
@graydon, I've implemented I had an abortive attempt at moving away from mutable fields in Also: I've had to add 2
|
Iterate over lines in a series of files. API (mostly) adopted from Python's fileinput module.
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.
…sy-float-literal-restriction, r=flip1995 Move check for lossy whole-number floats out of `excessive_precision` changelog: Add new lint `lossy_float_literal` to detect lossy whole number float literals and move it out of `excessive_precision` again. Fixes rust-lang#5201
As per https://github.com/mozilla/rust/wiki/Note-wanted-libraries.
Iterates over lines in a series of files, e.g. a basic
cat
The API is essentially a subset of Python's fileinput module, 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:
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.libcore/io.rs
seem to indicate using atmp
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 justfileinput.rs
after creating./tmp/
manually).