Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions src/uu/od/src/input_decoder.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map feels a bit unusual here since we’re updating two fields as a side effect.

How about using the ? operator to return early instead?

    let (n, p) = self
        .input
        .peek_read(self.data.as_mut_slice(), self.reserved_peek_length)?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so like that?

    pub fn peek_read(&mut self) -> io::Result<MemoryDecoder<'_>> {
        let (n, p) = self
            .input
            .peek_read(self.data.as_mut_slice(), self.reserved_peek_length)?;
        self.used_normal_length = n;
        self.used_peek_length = p;
        Ok(MemoryDecoder {
            data: &mut self.data,
            used_normal_length: self.used_normal_length,
            used_peek_length: self.used_peek_length,
            byte_order: self.byte_order,
        })
    }

Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,17 @@ where
/// calls `peek_read` on the internal stream to (re)fill the buffer. Returns a
/// `MemoryDecoder` providing access to the result or returns an i/o error.
pub fn peek_read(&mut self) -> io::Result<MemoryDecoder<'_>> {
match self
let (n, p) = self
.input
.peek_read(self.data.as_mut_slice(), self.reserved_peek_length)
{
Ok((n, p)) => {
self.used_normal_length = n;
self.used_peek_length = p;
Ok(MemoryDecoder {
data: &mut self.data,
used_normal_length: self.used_normal_length,
used_peek_length: self.used_peek_length,
byte_order: self.byte_order,
})
}
Err(e) => Err(e),
}
.peek_read(self.data.as_mut_slice(), self.reserved_peek_length)?;
self.used_normal_length = n;
self.used_peek_length = p;
Ok(MemoryDecoder {
data: &mut self.data,
used_normal_length: self.used_normal_length,
used_peek_length: self.used_peek_length,
byte_order: self.byte_order,
})
}
}

Expand Down
Loading