Skip to content

Commit 7db0256

Browse files
AerialXhomu
authored andcommitted
linux: remove I2CResult to appease newer rustc
Pull request: #11 Approved by: posborne
1 parent fb9c1bc commit 7db0256

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/linux.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ impl Error for LinuxI2CError {
8282
}
8383
}
8484

85-
type I2CResult<T> = Result<T, LinuxI2CError>;
86-
8785
impl AsRawFd for LinuxI2CDevice {
8886
fn as_raw_fd(&self) -> RawFd {
8987
self.devfile.as_raw_fd()
@@ -118,7 +116,7 @@ impl LinuxI2CDevice {
118116
/// (it is done internally). Calling this method is only
119117
/// necessary if you need to change the slave device and you do
120118
/// not want to create a new device.
121-
fn set_slave_address(&mut self, slave_address: u16) -> I2CResult<()> {
119+
fn set_slave_address(&mut self, slave_address: u16) -> Result<(), LinuxI2CError> {
122120
try!(ffi::i2c_set_slave_address(self.as_raw_fd(), slave_address));
123121
self.slave_address = slave_address;
124122
Ok(())
@@ -129,17 +127,17 @@ impl I2CDevice for LinuxI2CDevice {
129127
type Error = LinuxI2CError;
130128

131129
/// Read data from the device to fill the provided slice
132-
fn read(&mut self, data: &mut [u8]) -> I2CResult<()> {
130+
fn read(&mut self, data: &mut [u8]) -> Result<(), LinuxI2CError> {
133131
self.devfile.read(data).map_err(From::from).map(drop)
134132
}
135133

136134
/// Write the provided buffer to the device
137-
fn write(&mut self, data: &[u8]) -> I2CResult<()> {
135+
fn write(&mut self, data: &[u8]) -> Result<(), LinuxI2CError> {
138136
self.devfile.write(data).map_err(From::from).map(drop)
139137
}
140138

141139
/// This sends a single bit to the device, at the place of the Rd/Wr bit
142-
fn smbus_write_quick(&mut self, bit: bool) -> I2CResult<()> {
140+
fn smbus_write_quick(&mut self, bit: bool) -> Result<(), LinuxI2CError> {
143141
ffi::i2c_smbus_write_quick(self.as_raw_fd(), bit).map_err(From::from)
144142
}
145143

@@ -148,44 +146,44 @@ impl I2CDevice for LinuxI2CDevice {
148146
/// Some devices are so simple that this interface is enough; for
149147
/// others, it is a shorthand if you want to read the same register as in
150148
/// the previous SMBus command.
151-
fn smbus_read_byte(&mut self) -> I2CResult<u8> {
149+
fn smbus_read_byte(&mut self) -> Result<u8, LinuxI2CError> {
152150
ffi::i2c_smbus_read_byte(self.as_raw_fd()).map_err(From::from)
153151
}
154152

155153
/// Write a single byte to a sdevice, without specifying a device register
156154
///
157155
/// This is the opposite operation as smbus_read_byte. As with read_byte,
158156
/// no register is specified.
159-
fn smbus_write_byte(&mut self, value: u8) -> I2CResult<()> {
157+
fn smbus_write_byte(&mut self, value: u8) -> Result<(), LinuxI2CError> {
160158
ffi::i2c_smbus_write_byte(self.as_raw_fd(), value).map_err(From::from)
161159
}
162160

163161
/// Read a single byte from a device, from a designated register
164162
///
165163
/// The register is specified through the Comm byte.
166-
fn smbus_read_byte_data(&mut self, register: u8) -> I2CResult<u8> {
164+
fn smbus_read_byte_data(&mut self, register: u8) -> Result<u8, LinuxI2CError> {
167165
ffi::i2c_smbus_read_byte_data(self.as_raw_fd(), register).map_err(From::from)
168166
}
169167

170168
/// Write a single byte to a specific register on a device
171169
///
172170
/// The register is specified through the Comm byte.
173-
fn smbus_write_byte_data(&mut self, register: u8, value: u8) -> I2CResult<()> {
171+
fn smbus_write_byte_data(&mut self, register: u8, value: u8) -> Result<(), LinuxI2CError> {
174172
ffi::i2c_smbus_write_byte_data(self.as_raw_fd(), register, value).map_err(From::from)
175173
}
176174

177175
/// Read 2 bytes form a given register on a device
178-
fn smbus_read_word_data(&mut self, register: u8) -> I2CResult<u16> {
176+
fn smbus_read_word_data(&mut self, register: u8) -> Result<u16, LinuxI2CError> {
179177
ffi::i2c_smbus_read_word_data(self.as_raw_fd(), register).map_err(From::from)
180178
}
181179

182180
/// Write 2 bytes to a given register on a device
183-
fn smbus_write_word_data(&mut self, register: u8, value: u16) -> I2CResult<()> {
181+
fn smbus_write_word_data(&mut self, register: u8, value: u16) -> Result<(), LinuxI2CError> {
184182
ffi::i2c_smbus_write_word_data(self.as_raw_fd(), register, value).map_err(From::from)
185183
}
186184

187185
/// Select a register, send 16 bits of data to it, and read 16 bits of data
188-
fn smbus_process_word(&mut self, register: u8, value: u16) -> I2CResult<u16> {
186+
fn smbus_process_word(&mut self, register: u8, value: u16) -> Result<u16, LinuxI2CError> {
189187
ffi::i2c_smbus_process_call(self.as_raw_fd(), register, value).map_err(From::from)
190188
}
191189

@@ -194,7 +192,7 @@ impl I2CDevice for LinuxI2CDevice {
194192
/// The actual number of bytes available to read is returned in the count
195193
/// byte. This code returns a correctly sized vector containing the
196194
/// count bytes read from the device.
197-
fn smbus_read_block_data(&mut self, register: u8) -> I2CResult<Vec<u8>> {
195+
fn smbus_read_block_data(&mut self, register: u8) -> Result<Vec<u8>, LinuxI2CError> {
198196
ffi::i2c_smbus_read_block_data(self.as_raw_fd(), register).map_err(From::from)
199197
}
200198

@@ -203,13 +201,13 @@ impl I2CDevice for LinuxI2CDevice {
203201
/// The opposite of the Block Read command, this writes up to 32 bytes to
204202
/// a device, to a designated register that is specified through the
205203
/// Comm byte. The amount of data is specified in the Count byte.
206-
fn smbus_write_block_data(&mut self, register: u8, values: &[u8]) -> I2CResult<()> {
204+
fn smbus_write_block_data(&mut self, register: u8, values: &[u8]) -> Result<(), LinuxI2CError> {
207205
ffi::i2c_smbus_write_block_data(self.as_raw_fd(), register, values).map_err(From::from)
208206
}
209207

210208
/// Select a register, send 1 to 31 bytes of data to it, and reads
211209
/// 1 to 31 bytes of data from it.
212-
fn smbus_process_block(&mut self, register: u8, values: &[u8]) -> I2CResult<()> {
210+
fn smbus_process_block(&mut self, register: u8, values: &[u8]) -> Result<(), LinuxI2CError> {
213211
ffi::i2c_smbus_write_i2c_block_data(self.as_raw_fd(), register, values).map_err(From::from)
214212
}
215213
}

0 commit comments

Comments
 (0)