3 ms·
It would be silly and wasteful to read the whole file into memory just so I can iterate its lines. I'm not sure why that's an option you'd need to accomodate.
by rspeer 10y ago
It would be silly and wasteful to read the whole file into memory just so I can iterate its lines. I'm not sure why that's an option you'd need to accomodate.
However, many languages make a reasonable assumption that you can afford to fit each line in memory, and provide an obvious way to do this.
- steveklabnik 10y ago> I'm not sure why that's an option you'd need to accomodate. Again, it's about control. Maybe you're only loading a small configuration file, and so fetching it all in one go is better than dealing with a buffer. > an obvious way to do this. If you search for 'line' or 'lines' in rustdoc, the correct thing is right near the top, which will show you how to use it with BufRead.
- rspeer 10y ago> Maybe you're only loading a small configuration file, and so fetching it all in one go is better than dealing with a buffer. If it's small, it can't be that much worse to buffer. What's wrong with reasonable defaults? Can you tell me what it means to search for 'line' or 'lines' in rustdoc? Is this a command-line tool? I'm aware of the 'rustdoc' that generates documentation, but not of anything by that name that searches documentation, and Googling isn't turning up much of anything except the Rust book here. It would be great to have an offline way to search Rust documentation and examples, as things like this make it very hard to write Rust on a plane, for example. Googling often gives answers that are wrong or pre-1.0. You seem to have better luck at searching for the right things, perhaps because you are an expert in the language and know exactly what to search for. (Amusing related anecdote: I googled for "how to return self in rust" and got a suicide prevention website. Jeez, Google, it's not that bad.)
- steveklabnik 10y ago> Can you tell me what it means to search for 'line' or 'lines' in rustdoc? Rustdoc has a search bar at the top. with 'line' it's the third result, 'lines' is the first https://doc.rust-lang.org/stable/std/?search=lines https://doc.rust-lang.org/stable/std/?search=lines and the short description makes it clear that the first two results are irrelevant in this case. > It would be great to have an offline way to search Rust documentation and examples, It all works offline. These docs are pre-installed for you when you install Rust, and 'cargo doc' will generate them for your whole project. > perhaps because you are an expert in the language and know exactly what to search for. I copy-pasted my search term exactly in the previous post.
- rspeer 10y ago> I copy-pasted my search term exactly in the previous post. I'm bringing up a problem with how the language presents itself to beginners, not asking you to solve a specific problem for me. If searching is the answer to everything, then there needs to be a concerted effort to take Google-juice away from bad or deprecated answers. Incidentally, the search result you're describing for "lines" says "An iterator over the lines of an instance of BufRead.", which only appears to be the answer to "how do I iterate lines of a file?" if you already know what the answer is.
- steveklabnik 10y agoNo no, I very much appreciate it! I think we have two searches confused. When I meant "my exact query, when we were taking about Google, here: https://news.ycombinator.com/item?id=13585902 https://news.ycombinator.com/item?id=13585902 I find it interesting that we got different results. I thought "an iterator over lines" would be enough; maybe not.
- gphilip 10y ago> It would be great to have an offline way to search Rust documentation and examples, >> It all works offline. These docs are pre-installed for you when you install Rust, and 'cargo doc' will generate them for your whole project. Not by default, anymore[0], as I found out when I wanted to read the book offline. To set up offline documentation, do: rustup component add rust-docs # One-time thing Now to open the docs in a browser, do one of: rustup doc rustup doc --api rustup doc --book The second and third forms open up the API documentation and the book, respectively. Bookmark for one-click access. [0] https://users.rust-lang.org/t/psa-rust-documentation-is-now-optional-and-opt-in-when-installing-via-rustup/8072 https://users.rust-lang.org/t/psa-rust-documentation-is-now-...
- steveklabnik 10y agoGah, I always forget. I want that switched back.
- rspeer 10y ago