Skip to content

Commit 3e76395

Browse files
Morgan RoffMorganR
Morgan Roff
authored andcommitted
Remove try_ method prefixes
1 parent 112aa9e commit 3e76395

File tree

6 files changed

+43
-47
lines changed

6 files changed

+43
-47
lines changed

examples/transactional-i2c.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ where
2323
I2cOperation::Write(&[0xAB]),
2424
I2cOperation::Read(&mut read_buffer),
2525
];
26-
self.i2c.try_exec(ADDR, &mut ops).and(Ok(read_buffer[0]))
26+
self.i2c.exec(ADDR, &mut ops).and(Ok(read_buffer[0]))
2727
}
2828
}
2929

src/cdev_pin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,35 @@ impl CdevPin {
3636
impl embedded_hal::digital::OutputPin for CdevPin {
3737
type Error = gpio_cdev::errors::Error;
3838

39-
fn try_set_low(&mut self) -> Result<(), Self::Error> {
39+
fn set_low(&mut self) -> Result<(), Self::Error> {
4040
self.0.set_value(0)
4141
}
4242

43-
fn try_set_high(&mut self) -> Result<(), Self::Error> {
43+
fn set_high(&mut self) -> Result<(), Self::Error> {
4444
self.0.set_value(1)
4545
}
4646
}
4747

4848
impl embedded_hal::digital::InputPin for CdevPin {
4949
type Error = gpio_cdev::errors::Error;
5050

51-
fn try_is_high(&self) -> Result<bool, Self::Error> {
51+
fn is_high(&self) -> Result<bool, Self::Error> {
5252
if !self.1.is_active_low() {
5353
self.0.get_value().map(|val| val != 0)
5454
} else {
5555
self.0.get_value().map(|val| val == 0)
5656
}
5757
}
5858

59-
fn try_is_low(&self) -> Result<bool, Self::Error> {
60-
self.try_is_high().map(|val| !val)
59+
fn is_low(&self) -> Result<bool, Self::Error> {
60+
self.is_high().map(|val| !val)
6161
}
6262
}
6363

6464
impl embedded_hal::digital::IoPin<CdevPin, CdevPin> for CdevPin {
6565
type Error = gpio_cdev::errors::Error;
6666

67-
fn try_into_input_pin(self) -> Result<CdevPin, Self::Error> {
67+
fn into_input_pin(self) -> Result<CdevPin, Self::Error> {
6868
if self.1.direction() == gpio_cdev::LineDirection::In {
6969
return Ok(self);
7070
}
@@ -78,7 +78,7 @@ impl embedded_hal::digital::IoPin<CdevPin, CdevPin> for CdevPin {
7878
CdevPin::new(line.request(input_flags, 0, &consumer)?)
7979
}
8080

81-
fn try_into_output_pin(
81+
fn into_output_pin(
8282
self,
8383
state: embedded_hal::digital::PinState,
8484
) -> Result<CdevPin, Self::Error> {

src/lib.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct Delay;
6464
impl embedded_hal::blocking::delay::DelayUs<u8> for Delay {
6565
type Error = Infallible;
6666

67-
fn try_delay_us(&mut self, n: u8) -> Result<(), Self::Error> {
67+
fn delay_us(&mut self, n: u8) -> Result<(), Self::Error> {
6868
thread::sleep(Duration::new(0, u32(n) * 1000));
6969
Ok(())
7070
}
@@ -73,7 +73,7 @@ impl embedded_hal::blocking::delay::DelayUs<u8> for Delay {
7373
impl embedded_hal::blocking::delay::DelayUs<u16> for Delay {
7474
type Error = Infallible;
7575

76-
fn try_delay_us(&mut self, n: u16) -> Result<(), Self::Error> {
76+
fn delay_us(&mut self, n: u16) -> Result<(), Self::Error> {
7777
thread::sleep(Duration::new(0, u32(n) * 1000));
7878
Ok(())
7979
}
@@ -82,7 +82,7 @@ impl embedded_hal::blocking::delay::DelayUs<u16> for Delay {
8282
impl embedded_hal::blocking::delay::DelayUs<u32> for Delay {
8383
type Error = Infallible;
8484

85-
fn try_delay_us(&mut self, n: u32) -> Result<(), Self::Error> {
85+
fn delay_us(&mut self, n: u32) -> Result<(), Self::Error> {
8686
let secs = n / 1_000_000;
8787
let nsecs = (n % 1_000_000) * 1_000;
8888

@@ -94,7 +94,7 @@ impl embedded_hal::blocking::delay::DelayUs<u32> for Delay {
9494
impl embedded_hal::blocking::delay::DelayUs<u64> for Delay {
9595
type Error = Infallible;
9696

97-
fn try_delay_us(&mut self, n: u64) -> Result<(), Self::Error> {
97+
fn delay_us(&mut self, n: u64) -> Result<(), Self::Error> {
9898
let secs = n / 1_000_000;
9999
let nsecs = ((n % 1_000_000) * 1_000) as u32;
100100

@@ -106,7 +106,7 @@ impl embedded_hal::blocking::delay::DelayUs<u64> for Delay {
106106
impl embedded_hal::blocking::delay::DelayMs<u8> for Delay {
107107
type Error = Infallible;
108108

109-
fn try_delay_ms(&mut self, n: u8) -> Result<(), Self::Error> {
109+
fn delay_ms(&mut self, n: u8) -> Result<(), Self::Error> {
110110
thread::sleep(Duration::from_millis(u64(n)));
111111
Ok(())
112112
}
@@ -115,7 +115,7 @@ impl embedded_hal::blocking::delay::DelayMs<u8> for Delay {
115115
impl embedded_hal::blocking::delay::DelayMs<u16> for Delay {
116116
type Error = Infallible;
117117

118-
fn try_delay_ms(&mut self, n: u16) -> Result<(), Self::Error> {
118+
fn delay_ms(&mut self, n: u16) -> Result<(), Self::Error> {
119119
thread::sleep(Duration::from_millis(u64(n)));
120120
Ok(())
121121
}
@@ -124,7 +124,7 @@ impl embedded_hal::blocking::delay::DelayMs<u16> for Delay {
124124
impl embedded_hal::blocking::delay::DelayMs<u32> for Delay {
125125
type Error = Infallible;
126126

127-
fn try_delay_ms(&mut self, n: u32) -> Result<(), Self::Error> {
127+
fn delay_ms(&mut self, n: u32) -> Result<(), Self::Error> {
128128
thread::sleep(Duration::from_millis(u64(n)));
129129
Ok(())
130130
}
@@ -133,7 +133,7 @@ impl embedded_hal::blocking::delay::DelayMs<u32> for Delay {
133133
impl embedded_hal::blocking::delay::DelayMs<u64> for Delay {
134134
type Error = Infallible;
135135

136-
fn try_delay_ms(&mut self, n: u64) -> Result<(), Self::Error> {
136+
fn delay_ms(&mut self, n: u64) -> Result<(), Self::Error> {
137137
thread::sleep(Duration::from_millis(n));
138138
Ok(())
139139
}
@@ -176,7 +176,7 @@ impl I2cdev {
176176
impl embedded_hal::blocking::i2c::Read for I2cdev {
177177
type Error = i2cdev::linux::LinuxI2CError;
178178

179-
fn try_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
179+
fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
180180
self.set_address(address)?;
181181
self.inner.read(buffer)
182182
}
@@ -185,7 +185,7 @@ impl embedded_hal::blocking::i2c::Read for I2cdev {
185185
impl embedded_hal::blocking::i2c::Write for I2cdev {
186186
type Error = i2cdev::linux::LinuxI2CError;
187187

188-
fn try_write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> {
188+
fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> {
189189
self.set_address(address)?;
190190
self.inner.write(bytes)
191191
}
@@ -194,7 +194,7 @@ impl embedded_hal::blocking::i2c::Write for I2cdev {
194194
impl embedded_hal::blocking::i2c::WriteRead for I2cdev {
195195
type Error = i2cdev::linux::LinuxI2CError;
196196

197-
fn try_write_read(
197+
fn write_read(
198198
&mut self,
199199
address: u8,
200200
bytes: &[u8],
@@ -209,11 +209,7 @@ impl embedded_hal::blocking::i2c::WriteRead for I2cdev {
209209
impl embedded_hal::blocking::i2c::Transactional for I2cdev {
210210
type Error = i2cdev::linux::LinuxI2CError;
211211

212-
fn try_exec(
213-
&mut self,
214-
address: u8,
215-
operations: &mut [I2cOperation],
216-
) -> Result<(), Self::Error> {
212+
fn exec(&mut self, address: u8, operations: &mut [I2cOperation]) -> Result<(), Self::Error> {
217213
// Map operations from generic to linux objects
218214
let mut messages: Vec<_> = operations
219215
.as_mut()
@@ -263,7 +259,7 @@ impl Spidev {
263259
impl embedded_hal::blocking::spi::Transfer<u8> for Spidev {
264260
type Error = io::Error;
265261

266-
fn try_transfer<'b>(&mut self, buffer: &'b mut [u8]) -> io::Result<&'b [u8]> {
262+
fn transfer<'b>(&mut self, buffer: &'b mut [u8]) -> io::Result<&'b [u8]> {
267263
let tx = buffer.to_owned();
268264
self.0
269265
.transfer(&mut SpidevTransfer::read_write(&tx, buffer))?;
@@ -274,7 +270,7 @@ impl embedded_hal::blocking::spi::Transfer<u8> for Spidev {
274270
impl embedded_hal::blocking::spi::Write<u8> for Spidev {
275271
type Error = io::Error;
276272

277-
fn try_write(&mut self, buffer: &[u8]) -> io::Result<()> {
273+
fn write(&mut self, buffer: &[u8]) -> io::Result<()> {
278274
self.0.write_all(buffer)
279275
}
280276
}
@@ -285,7 +281,7 @@ pub use embedded_hal::blocking::spi::Operation as SpiOperation;
285281
impl embedded_hal::blocking::spi::Transactional<u8> for Spidev {
286282
type Error = io::Error;
287283

288-
fn try_exec<'a>(&mut self, operations: &mut [SpiOperation<'a, u8>]) -> Result<(), Self::Error> {
284+
fn exec<'a>(&mut self, operations: &mut [SpiOperation<'a, u8>]) -> Result<(), Self::Error> {
289285
// Map types from generic to linux objects
290286
let mut messages: Vec<_> = operations
291287
.iter_mut()

src/serial.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn translate_io_errors(err: std::io::Error) -> nb::Error<IoErrorKind> {
3232
impl embedded_hal::serial::Read<u8> for Serial {
3333
type Error = IoErrorKind;
3434

35-
fn try_read(&mut self) -> nb::Result<u8, Self::Error> {
35+
fn read(&mut self) -> nb::Result<u8, Self::Error> {
3636
let mut buffer = [0; 1];
3737
let bytes_read = self.0.read(&mut buffer).map_err(translate_io_errors)?;
3838
if bytes_read == 1 {
@@ -46,12 +46,12 @@ impl embedded_hal::serial::Read<u8> for Serial {
4646
impl embedded_hal::serial::Write<u8> for Serial {
4747
type Error = IoErrorKind;
4848

49-
fn try_write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
49+
fn write(&mut self, word: u8) -> nb::Result<(), Self::Error> {
5050
self.0.write(&[word]).map_err(translate_io_errors)?;
5151
Ok(())
5252
}
5353

54-
fn try_flush(&mut self) -> nb::Result<(), Self::Error> {
54+
fn flush(&mut self) -> nb::Result<(), Self::Error> {
5555
self.0.flush().map_err(translate_io_errors)
5656
}
5757
}
@@ -75,20 +75,20 @@ mod test {
7575
#[test]
7676
fn test_empty_read() {
7777
let (mut _master, mut serial) = create_pty_and_serial();
78-
assert_eq!(Err(nb::Error::WouldBlock), serial.try_read());
78+
assert_eq!(Err(nb::Error::WouldBlock), serial.read());
7979
}
8080

8181
#[test]
8282
fn test_read() {
8383
let (mut master, mut serial) = create_pty_and_serial();
8484
master.write(&[1]).expect("Write failed");
85-
assert_eq!(Ok(1), serial.try_read());
85+
assert_eq!(Ok(1), serial.read());
8686
}
8787

8888
#[test]
8989
fn test_write() {
9090
let (mut master, mut serial) = create_pty_and_serial();
91-
serial.try_write(2).expect("Write failed");
91+
serial.write(2).expect("Write failed");
9292
let mut buf = [0; 2];
9393
assert_eq!(1, master.read(&mut buf).unwrap());
9494
assert_eq!(buf, [2, 0]);

src/sysfs_pin.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,40 @@ impl SysfsPin {
2929
impl embedded_hal::digital::OutputPin for SysfsPin {
3030
type Error = sysfs_gpio::Error;
3131

32-
fn try_set_low(&mut self) -> Result<(), Self::Error> {
32+
fn set_low(&mut self) -> Result<(), Self::Error> {
3333
self.0.set_value(0)
3434
}
3535

36-
fn try_set_high(&mut self) -> Result<(), Self::Error> {
36+
fn set_high(&mut self) -> Result<(), Self::Error> {
3737
self.0.set_value(1)
3838
}
3939
}
4040

4141
impl embedded_hal::digital::InputPin for SysfsPin {
4242
type Error = sysfs_gpio::Error;
4343

44-
fn try_is_high(&self) -> Result<bool, Self::Error> {
44+
fn is_high(&self) -> Result<bool, Self::Error> {
4545
if !self.0.get_active_low()? {
4646
self.0.get_value().map(|val| val != 0)
4747
} else {
4848
self.0.get_value().map(|val| val == 0)
4949
}
5050
}
5151

52-
fn try_is_low(&self) -> Result<bool, Self::Error> {
53-
self.try_is_high().map(|val| !val)
52+
fn is_low(&self) -> Result<bool, Self::Error> {
53+
self.is_high().map(|val| !val)
5454
}
5555
}
5656

5757
impl embedded_hal::digital::IoPin<SysfsPin, SysfsPin> for SysfsPin {
5858
type Error = sysfs_gpio::Error;
5959

60-
fn try_into_input_pin(self) -> Result<SysfsPin, Self::Error> {
60+
fn into_input_pin(self) -> Result<SysfsPin, Self::Error> {
6161
self.set_direction(sysfs_gpio::Direction::In)?;
6262
Ok(self)
6363
}
6464

65-
fn try_into_output_pin(
65+
fn into_output_pin(
6666
self,
6767
state: embedded_hal::digital::PinState,
6868
) -> Result<SysfsPin, Self::Error> {

src/timer.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl CountDown for SysTimer {
3131
type Error = Infallible;
3232
type Time = Duration;
3333

34-
fn try_start<T>(&mut self, count: T) -> Result<(), Self::Error>
34+
fn start<T>(&mut self, count: T) -> Result<(), Self::Error>
3535
where
3636
T: Into<Self::Time>,
3737
{
@@ -40,7 +40,7 @@ impl CountDown for SysTimer {
4040
Ok(())
4141
}
4242

43-
fn try_wait(&mut self) -> nb::Result<(), Self::Error> {
43+
fn wait(&mut self) -> nb::Result<(), Self::Error> {
4444
if (Instant::now() - self.start) >= self.duration {
4545
// Restart the timer to fulfill the contract by `Periodic`
4646
self.start = Instant::now();
@@ -63,8 +63,8 @@ mod tests {
6363
fn test_delay() {
6464
let mut timer = SysTimer::new();
6565
let before = Instant::now();
66-
timer.try_start(Duration::from_millis(100)).unwrap();
67-
nb::block!(timer.try_wait()).unwrap();
66+
timer.start(Duration::from_millis(100)).unwrap();
67+
nb::block!(timer.wait()).unwrap();
6868
let after = Instant::now();
6969
let duration_ms = (after - before).as_millis();
7070
assert!(duration_ms >= 100);
@@ -76,13 +76,13 @@ mod tests {
7676
fn test_periodic() {
7777
let mut timer = SysTimer::new();
7878
let before = Instant::now();
79-
timer.try_start(Duration::from_millis(100)).unwrap();
80-
nb::block!(timer.try_wait()).unwrap();
79+
timer.start(Duration::from_millis(100)).unwrap();
80+
nb::block!(timer.wait()).unwrap();
8181
let after1 = Instant::now();
8282
let duration_ms_1 = (after1 - before).as_millis();
8383
assert!(duration_ms_1 >= 100);
8484
assert!(duration_ms_1 < 500);
85-
nb::block!(timer.try_wait()).unwrap();
85+
nb::block!(timer.wait()).unwrap();
8686
let after2 = Instant::now();
8787
let duration_ms_2 = (after2 - after1).as_millis();
8888
assert!(duration_ms_2 >= 100);

0 commit comments

Comments
 (0)