I'd recommend one of two solutions, one is a match guard: match reader.read(buf) { Ok(cnt) => { /* ... */ } Err(ref e) if e.kind == io::EndOfFile => { /* ... */ } Err(e) => return Err(e) }
and the other would be to home-grow your own macro if you find yourself writing the same pattern frequently. On Mon, Feb 3, 2014 at 7:25 PM, Palmer Cox <palmer...@gmail.com> wrote: > I like this change quite a bit. However, is there a more succinct way than > the following to take an action on EOF: > > match reader.read(buff) { > Ok(cnt) => { > // Do something > } > Err(io_error) => match io_error.kind { > EndOfFile => { > // Do something for EOF > } > _ => return Err(io_error) > } > } > > -Palmer Cox > > > > On Mon, Feb 3, 2014 at 9:19 PM, Alex Crichton <a...@crichton.co> wrote: >> >> > By returning a Result from all function calls, it's not much cleaner >> > to handle errors >> >> Oops, wrong word there, I meant to indicate that it *is* much cleaner >> to handle errors with Result rather than conditions. >> _______________________________________________ >> Rust-dev mailing list >> Rust-dev@mozilla.org >> https://mail.mozilla.org/listinfo/rust-dev > > _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev