Hello,

Sorry for the bikesheddy question, but coming from a Haskell perspective
it's strange that io::Reader::read_byte returns (1) an int, when the value
you're reading is a byte, and (2) "a negative value" on error/EOF.  The
unspecified sentinel value means the pattern match needs to look like:
  match r.read_byte() {
    i if i < 0 => ...
    i => { let b = i as u8; ... }

It would seem more natural to me for it to return an Option<u8>, but that
leads to two questions:

1) Is it more Rusty to use types like this instead of sentinels?  My
aesthetics aren't adapted to Rust yet.

2) Is an Option<u8> implemented as a pair of (type, value) or is it packed
into a single word?  (In the former case, maybe efficiency is the reason
for the original "int" return value.)  And is this sort of thing even
specified by Rust or is it up to the compiler to optimize or not?  Looking
at the tracker I found https://github.com/mozilla/rust/issues/5977 , which
seems like basically the same thing.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to