Add Hash::from_inner and prevent double allocation in FromHex using it#40
Conversation
src/hex.rs
Outdated
| fn next_back(&mut self) -> Option<Result<u8, Error>> { | ||
| let current_len = self.sl.len(); | ||
| if current_len % 2 == 1 { | ||
| Some(Err(Error::OddLengthString(self.sl.len()))) |
There was a problem hiding this comment.
Why not use current_len here?
There was a problem hiding this comment.
I took the liberty to fix it in a separate commit, do you think I should squash it into Andrew's commit?
| let current_len = self.sl.len(); | ||
| if current_len % 2 == 1 { | ||
| Some(Err(Error::OddLengthString(self.sl.len()))) | ||
| } else if self.sl.is_empty() { |
There was a problem hiding this comment.
Why not use current_len here as well? I would start with if current_len == 0 { ... } else if current_len % 2 == 1 { ... } personally.
There was a problem hiding this comment.
But I see this is mirroring the impl of Iterator, which if fine I guess.
|
Can't approve my own PR. So ACK d71dd99 |
d71dd99 to
3dc8dfc
Compare
sgeisler
left a comment
There was a problem hiding this comment.
LGTM, please tell me if I should squash the fixup commit and reapprove.
| impl<'a> DoubleEndedIterator for HexIterator<'a> { | ||
| fn next_back(&mut self) -> Option<Result<u8, Error>> { | ||
| let current_len = self.sl.len(); | ||
| if current_len % 2 == 1 { |
There was a problem hiding this comment.
Imo this check shouldn't happen for every element, but I'll open a separate PR.
src/hex.rs
Outdated
| fn next_back(&mut self) -> Option<Result<u8, Error>> { | ||
| let current_len = self.sl.len(); | ||
| if current_len % 2 == 1 { | ||
| Some(Err(Error::OddLengthString(self.sl.len()))) |
There was a problem hiding this comment.
I took the liberty to fix it in a separate commit, do you think I should squash it into Andrew's commit?
No description provided.