-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Use size_hint when using read_to_end
on something that impl's Read
#113927
Comments
@rustbot label T-libs I-slow |
If you means Lines 766 to 769 in 1c44af9
For the default read_to_end , because we don't have a default method to get the guessing size? |
@chenyukang, yes I noticed the addition to
It may be as simple as surfacing the As a side note, I wonder if the ability to define functions with optional parameters will simplify things in general. |
I am very confused by this issue, maybe you can clear things up.
My basic response to this is: Why would we do this? Isn't it just as much work to call
If the file is larger than memory, surely the size hint would also be larger than memory, and thus acting on it would just OOM faster. So I don't see how a size hint helps here. If you want to iterate through a file larger than memory, use
You're looking for https://github.com/rust-lang/rfcs, you may find some interesting reading material by searching the PRs on that repo. I did a quick skim and I didn't find anything about optional arguments specifically, but I did find a lot of discussion on an RFC about keyword arguments. |
Ah, sorry, I could have been clearer.
... where those Does that help? Because |
It sounds to me like you don't want But more generally, this sounds like you're suggesting a new API, in which case you should follow https://std-dev-guide.rust-lang.org/development/feature-lifecycle.html or try to start a conversation about your idea on https://internals.rust-lang.org/. This repo's issue tracker is not the right place for the kind of discussion you're trying to have; there's just not the right audience here. You can find the right audience for developing a new feature at those links. |
Okay, thanks for the guidance! I'll close this off then. |
In the
default_read_to_end
implementation, a parameter forsize_hint
is available.However, when doing the actual
read_to_end
, it's initialized withNone
.When using the the below pattern to implement a custom iterator over a file, when the max possible line length is known, it would be helpful to make use of the
size_hint
parameter, assuming it's a slightly faster path (?).This will be, in spirit, a continuation of #89165, #89582, and #110655
In short, I'm asking if the ability to pass a
size_hint
ofx
(from thetake
) into theread_to_end
function will be useful, and if it'd be slightly better performance wise?The text was updated successfully, but these errors were encountered: