I just saw the following change in a pull request:
- .ok_or(Error::new(ErrorKind::Other, \"Decode error\"));
+ .ok_o
The signature of std::io::Error::new is
fn new(kind: ErrorKind, error: E) -> Error
where
E: Into>,
This means that Error::new(ErrorKind::Other, "Decode error") allocates memory on the heap because error needs to be converted into Box to be of any use.
Consequently, this pull request removes unneeded memory allocation/deallocation when the Result value is Result::Ok.