Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
73: Use File.read_exact instead of File.read r=eldruin a=jath03

As the documentation says, `I2CDevice.read` is supposed to "fill the provided slice", which `File.read` on it's own doesn't do.  Using `File.read_exact` instead will accomplish the intended behavior.
https://doc.rust-lang.org/std/fs/struct.File.html#method.read_exact-1

Co-authored-by: Jack <[email protected]>
  • Loading branch information
bors[bot] and jath03 authored Jun 7, 2022
2 parents 385ea5d + f6858e4 commit efb1090
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]

- Updated nix to version `0.24`; only use the `ioctl` feature.
- Use `File.read_exact` instead of `File.read` in `LinuxI2CDevice.read` so that the buffer is filled.

## [v0.5.1] - 2021-11-22

Expand Down
2 changes: 1 addition & 1 deletion src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl I2CDevice for LinuxI2CDevice {

/// Read data from the device to fill the provided slice
fn read(&mut self, data: &mut [u8]) -> Result<(), LinuxI2CError> {
self.devfile.read(data).map_err(From::from).map(drop)
self.devfile.read_exact(data).map_err(From::from).map(drop)
}

/// Write the provided buffer to the device
Expand Down

0 comments on commit efb1090

Please sign in to comment.