Rust has the paradigm of avoiding implicit functionality, which is pretty good. So the code is readable and good to parse by human eyes.
But I always have problems finding all positions where a function returns when there's no explicit return
statement but a missing semicolon.
If I have a complex function with nested if
and match
blocks, it's hard to find these in the code.
I would like, if I could mark these with some (optional) symbol, e.g. ->
A real world example:
match self.stream.write_all(&buff[..]) {
Err(e) => Err(Error::Io(e)),
Ok(_s) => {
let mut reply = vec![0; MODBUS_HEADER_SIZE + expected_bytes + 2];
match self.stream.read(&mut reply) {
Err(e) => Err(Error::Io(e)),
Ok(_s) => {
let resp_hd = try!(decode(&reply[..MODBUS_HEADER_SIZE]));
try!(Transport::validate_response_header(&header, &resp_hd));
try!(Transport::validate_response_code(&buff, &reply[..]));
Transport::get_reply_data(&reply, expected_bytes)
}
}
}
},
Err(Error::InvalidData)
vs.
match self.stream.write_all(&buff[..]) {
Err(e) => Err(Error::Io(e)) ->,
Ok(_s) => {
let mut reply = vec![0; MODBUS_HEADER_SIZE + expected_bytes + 2];
match self.stream.read(&mut reply) {
Err(e) => Err(Error::Io(e)) ->,
Ok(_s) => {
let resp_hd = try!(decode(&reply[..MODBUS_HEADER_SIZE]));
try!(Transport::validate_response_header(&header, &resp_hd));
try!(Transport::validate_response_code(&buff, &reply[..]));
Transport::get_reply_data(&reply, expected_bytes) ->
}
}
}
},
Err(Error::InvalidData) ->
I don't know if it is possible with the current syntax. What do you think?