Handling EOF of Read::read

Hello Rustaceans.
I was reading tokio tutorial and I was surprised why they read method reports end of file (EOF) as 0. The answer was "it is same as in std library". So now I am here and asking the same (maybe stupid) question. I would expect that EOF will be reported by an Option or some another more verbose enum e.g. EOF/ReadBytes(usize). What I think would be the best is usage of core::num::NonZeroUsize so in the case of Option Option<core::num::NonZeroUsize>, which would give EOF without extra memory penalty.

I am aware of that posix read function returns 0 in two cases and the only one means EOF (very sad). The second means that read buffer has zero size (which in my opinion is not practically useful).

So with all my rust knowledge (very little to be honest) I think there is a more idiomatic way to express EOF than let user match zero value.

So does my idea make sense?
Is there any reason except BC break which makes this idea not useful?

Mirroring the standard library is why we return zero, but I am open to consider changing it, since we are already changing the IO traits. Did you have an opinion on #2716 that I also linked on the issue?

Note: I am Darksonn from the GitHub issue.

To answer your question more directly, I think the biggest drawback is the lack of familiarity.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.