-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Add size hint methods on Reader and Writer #46
Conversation
One thing I'd be a little worried about is how wordy writer wrappers will become. When a type wraps an inner writer, it already has to remember to override I personally think that this belongs as a separate trait because most writers aren't pre-allocating space. Essentially |
Pre-allocating space is also important when writing to the disk. If |
If a writer wrapper forgets to override
This doesn’t really work for generic code that wants to accept any writer. The point is to provide this information to the writer, and leave it to the implementation to decide what to do with it (if anything). If this is a separate trait, a writer that doesn’t do anything with this information would still need to implement the trait in order to be used with code that provides this information. |
I suppose a separate trait would work if we have "specialization" (rust-lang/rust#7059). |
* Add size_hint on Reader, like on Iterator * Highlight the precedent of Iterator::size_hint * Rename reserve_additional to reserve * Use an estimated range (lower bound and optional upper bound) like size_hint, rather than a single estimated number.
I just pushed an update. The text is almost completely rewritten, but the spirit is the same. The main changes are:
|
Discussed at https://github.com/mozilla/rust/wiki/Meeting-weekly-2014-06-10, the feeling is that none of us have seen precedent for these operations in other I/O libraries and we don't want to risk breaking the mold here. Not accepted. Sorry. |
Unfortunately it seems that no one was "championing" this RFC when it was discussed. I accept the team’s decision, but just for my curiosity: was there a precedent for the |
@SimonSapin I don't know if there is precedent for iterator size hints. @thestinger might know. |
Python has a size hint for iterators, and Rust's size hint was inspired by that feature. I altered it to provide both a lower bound and optional upper bound, because Python's flexible definition can be problematic: |
Add missing backtick
Registry / Container reform
No description provided.