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.
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?