hzgrow-r502
hzgrow-r502 copied to clipboard
Better API, it gets Results
Currently, R502::send_command
will return an Ok(T)
result if it successfully receives a reply from the device. However, it should rather return an Ok(T)
only if it receives a reply and that reply has a status code of Success
. This is to enable chaining calls like so:
let search_result = Ok(())
.and_then(|_| r502.authenticate(0x00000000))
.and_then(|_| r502.wait_for_image())
.and_then(|_| r502.process_image(Buffer::Buf1))
.and_then(|_| r502.search(Buffer::Buf1, 0, 0xff));
match search_result {
Ok(result) => launch_missiles(),
Err(Error::ReplyError(..)) => /* request was responded to, but with a status code other than 0x00 */,
Err(Error::CommsError(..)) => /* error from the underlying connection */
}