Skip to content

Commit efb1090

Browse files
bors[bot]jath03
andauthored
Merge #73
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]>
2 parents 385ea5d + f6858e4 commit efb1090

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Versioning](https://semver.org/spec/v2.0.0.html).
99
## [Unreleased]
1010

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

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

src/linux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl I2CDevice for LinuxI2CDevice {
175175

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

181181
/// Write the provided buffer to the device

0 commit comments

Comments
 (0)