Skip to content

Commit b99fad8

Browse files
bors[bot]Dirbaio
andauthored
Merge #268
268: Remove try_ prefix. r=eldruin a=Dirbaio This removes the `try_` prefix from all the trait method names, after discussion on issue #177 . Co-authored-by: Dario Nieuwenhuis <[email protected]>
2 parents 1d22385 + 9819662 commit b99fad8

File tree

18 files changed

+161
-167
lines changed

18 files changed

+161
-167
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
### Changed
1515
- Swap PWM channel arguments to references
16+
- All trait methods have been renamed to remove the `try_` prefix (i.e. `try_send` -> `send`) for consistency.
1617

1718
## [v1.0.0-alpha.4] - 2020-11-11
1819

src/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub trait Channel<ADC> {
7373
/// {
7474
/// type Error = ();
7575
///
76-
/// fn try_read(&mut self, pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
76+
/// fn read(&mut self, pin: &mut PIN) -> nb::Result<WORD, Self::Error> {
7777
/// let chan = 1 << pin.channel();
7878
/// self.power_up();
7979
/// let result = self.do_conversion(chan);
@@ -90,5 +90,5 @@ pub trait OneShot<ADC, Word, Pin: Channel<ADC>> {
9090
///
9191
/// This method takes a `Pin` reference, as it is expected that the ADC will be able to sample
9292
/// whatever channel underlies the pin.
93-
fn try_read(&mut self, pin: &mut Pin) -> nb::Result<Word, Self::Error>;
93+
fn read(&mut self, pin: &mut Pin) -> nb::Result<Word, Self::Error>;
9494
}

src/blocking/delay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub trait DelayMs<UXX> {
1616
type Error;
1717

1818
/// Pauses execution for `ms` milliseconds
19-
fn try_delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error>;
19+
fn delay_ms(&mut self, ms: UXX) -> Result<(), Self::Error>;
2020
}
2121

2222
/// Microsecond delay
@@ -28,5 +28,5 @@ pub trait DelayUs<UXX> {
2828
type Error;
2929

3030
/// Pauses execution for `us` microseconds
31-
fn try_delay_us(&mut self, us: UXX) -> Result<(), Self::Error>;
31+
fn delay_us(&mut self, us: UXX) -> Result<(), Self::Error>;
3232
}

src/blocking/i2c.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//! {
3131
//! # type Error = ();
3232
//! #
33-
//! fn try_write(&mut self, addr: u8, output: &[u8]) -> Result<(), Self::Error> {
33+
//! fn write(&mut self, addr: u8, output: &[u8]) -> Result<(), Self::Error> {
3434
//! // ...
3535
//! # Ok(())
3636
//! }
@@ -40,7 +40,7 @@
4040
//! {
4141
//! # type Error = ();
4242
//! #
43-
//! fn try_write(&mut self, addr: u16, output: &[u8]) -> Result<(), Self::Error> {
43+
//! fn write(&mut self, addr: u16, output: &[u8]) -> Result<(), Self::Error> {
4444
//! // ...
4545
//! # Ok(())
4646
//! }
@@ -66,7 +66,7 @@
6666
//! pub fn read_temperature(&mut self) -> Result<u8, E> {
6767
//! let mut temp = [0];
6868
//! self.i2c
69-
//! .try_write_read(ADDR, &[TEMP_REGISTER], &mut temp)
69+
//! .write_read(ADDR, &[TEMP_REGISTER], &mut temp)
7070
//! .and(Ok(temp[0]))
7171
//! }
7272
//! }
@@ -89,7 +89,7 @@
8989
//! pub fn read_temperature(&mut self) -> Result<u8, E> {
9090
//! let mut temp = [0];
9191
//! self.i2c
92-
//! .try_write_read(ADDR, &[TEMP_REGISTER], &mut temp)
92+
//! .write_read(ADDR, &[TEMP_REGISTER], &mut temp)
9393
//! .and(Ok(temp[0]))
9494
//! }
9595
//! }
@@ -135,7 +135,7 @@ pub trait Read<A: AddressMode = SevenBitAddress> {
135135
/// - `MAK` = master acknowledge
136136
/// - `NMAK` = master no acknowledge
137137
/// - `SP` = stop condition
138-
fn try_read(&mut self, address: A, buffer: &mut [u8]) -> Result<(), Self::Error>;
138+
fn read(&mut self, address: A, buffer: &mut [u8]) -> Result<(), Self::Error>;
139139
}
140140

141141
/// Blocking write
@@ -159,7 +159,7 @@ pub trait Write<A: AddressMode = SevenBitAddress> {
159159
/// - `SAK` = slave acknowledge
160160
/// - `Bi` = ith byte of data
161161
/// - `SP` = stop condition
162-
fn try_write(&mut self, address: A, bytes: &[u8]) -> Result<(), Self::Error>;
162+
fn write(&mut self, address: A, bytes: &[u8]) -> Result<(), Self::Error>;
163163
}
164164

165165
/// Blocking write (iterator version)
@@ -172,7 +172,7 @@ pub trait WriteIter<A: AddressMode = SevenBitAddress> {
172172
/// # I2C Events (contract)
173173
///
174174
/// Same as `Write`
175-
fn try_write_iter<B>(&mut self, address: A, bytes: B) -> Result<(), Self::Error>
175+
fn write_iter<B>(&mut self, address: A, bytes: B) -> Result<(), Self::Error>
176176
where
177177
B: IntoIterator<Item = u8>;
178178
}
@@ -204,7 +204,7 @@ pub trait WriteRead<A: AddressMode = SevenBitAddress> {
204204
/// - `MAK` = master acknowledge
205205
/// - `NMAK` = master no acknowledge
206206
/// - `SP` = stop condition
207-
fn try_write_read(
207+
fn write_read(
208208
&mut self,
209209
address: A,
210210
bytes: &[u8],
@@ -223,7 +223,7 @@ pub trait WriteIterRead<A: AddressMode = SevenBitAddress> {
223223
/// # I2C Events (contract)
224224
///
225225
/// Same as the `WriteRead` trait
226-
fn try_write_iter_read<B>(
226+
fn write_iter_read<B>(
227227
&mut self,
228228
address: A,
229229
bytes: B,
@@ -264,11 +264,8 @@ pub trait Transactional<A: AddressMode = SevenBitAddress> {
264264
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
265265
/// - `SR` = repeated start condition
266266
/// - `SP` = stop condition
267-
fn try_exec<'a>(
268-
&mut self,
269-
address: A,
270-
operations: &mut [Operation<'a>],
271-
) -> Result<(), Self::Error>;
267+
fn exec<'a>(&mut self, address: A, operations: &mut [Operation<'a>])
268+
-> Result<(), Self::Error>;
272269
}
273270

274271
/// Transactional I2C interface (iterator version).
@@ -291,7 +288,7 @@ pub trait TransactionalIter<A: AddressMode = SevenBitAddress> {
291288
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
292289
/// - `SR` = repeated start condition
293290
/// - `SP` = stop condition
294-
fn try_exec_iter<'a, O>(&mut self, address: A, operations: O) -> Result<(), Self::Error>
291+
fn exec_iter<'a, O>(&mut self, address: A, operations: O) -> Result<(), Self::Error>
295292
where
296293
O: IntoIterator<Item = Operation<'a>>;
297294
}
@@ -310,7 +307,7 @@ pub trait TransactionalIter<A: AddressMode = SevenBitAddress> {
310307
///
311308
/// impl i2c::Transactional<i2c::SevenBitAddress> for I2c1 {
312309
/// # type Error = ();
313-
/// fn try_exec<'a>(
310+
/// fn exec<'a>(
314311
/// &mut self,
315312
/// address: i2c::SevenBitAddress,
316313
/// operations: &mut [i2c::Operation<'a>],
@@ -327,7 +324,7 @@ pub trait TransactionalIter<A: AddressMode = SevenBitAddress> {
327324
/// use i2c::Write;
328325
///
329326
/// let mut i2c1 = I2c1{};
330-
/// i2c1.try_write(0x01, &[0xAB, 0xCD]).unwrap();
327+
/// i2c1.write(0x01, &[0xAB, 0xCD]).unwrap();
331328
/// ```
332329
pub mod transactional {
333330
use super::{AddressMode, Operation, Read, Transactional, Write, WriteRead};
@@ -343,8 +340,8 @@ pub mod transactional {
343340
{
344341
type Error = E;
345342

346-
fn try_write(&mut self, address: A, bytes: &[u8]) -> Result<(), Self::Error> {
347-
self.try_exec(address, &mut [Operation::Write(bytes)])
343+
fn write(&mut self, address: A, bytes: &[u8]) -> Result<(), Self::Error> {
344+
self.exec(address, &mut [Operation::Write(bytes)])
348345
}
349346
}
350347

@@ -355,8 +352,8 @@ pub mod transactional {
355352
{
356353
type Error = E;
357354

358-
fn try_read(&mut self, address: A, buffer: &mut [u8]) -> Result<(), Self::Error> {
359-
self.try_exec(address, &mut [Operation::Read(buffer)])
355+
fn read(&mut self, address: A, buffer: &mut [u8]) -> Result<(), Self::Error> {
356+
self.exec(address, &mut [Operation::Read(buffer)])
360357
}
361358
}
362359

@@ -367,13 +364,13 @@ pub mod transactional {
367364
{
368365
type Error = E;
369366

370-
fn try_write_read(
367+
fn write_read(
371368
&mut self,
372369
address: A,
373370
bytes: &[u8],
374371
buffer: &mut [u8],
375372
) -> Result<(), Self::Error> {
376-
self.try_exec(
373+
self.exec(
377374
address,
378375
&mut [Operation::Write(bytes), Operation::Read(buffer)],
379376
)

src/blocking/rng.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ pub trait Read {
1212
///
1313
/// If this function returns an error, it is unspecified how many bytes it has read, but it
1414
/// will never read more than would be necessary to completely fill the buffer.
15-
fn try_read(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error>;
15+
fn read(&mut self, buffer: &mut [u8]) -> Result<(), Self::Error>;
1616
}

src/blocking/serial.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ pub trait Write<Word> {
1010
/// An implementation can choose to buffer the write, returning `Ok(())`
1111
/// after the complete slice has been written to a buffer, but before all
1212
/// words have been sent via the serial interface. To make sure that
13-
/// everything has been sent, call [`try_bflush`] after this function returns.
13+
/// everything has been sent, call [`bflush`] after this function returns.
1414
///
15-
/// [`try_bflush`]: #tymethod.bflush
16-
fn try_bwrite_all(&mut self, buffer: &[Word]) -> Result<(), Self::Error>;
15+
/// [`bflush`]: #tymethod.bflush
16+
fn bwrite_all(&mut self, buffer: &[Word]) -> Result<(), Self::Error>;
1717

1818
/// Block until the serial interface has sent all buffered words
19-
fn try_bflush(&mut self) -> Result<(), Self::Error>;
19+
fn bflush(&mut self) -> Result<(), Self::Error>;
2020
}
2121

2222
/// Blocking serial write
@@ -38,16 +38,16 @@ pub mod write {
3838
{
3939
type Error = S::Error;
4040

41-
fn try_bwrite_all(&mut self, buffer: &[Word]) -> Result<(), Self::Error> {
41+
fn bwrite_all(&mut self, buffer: &[Word]) -> Result<(), Self::Error> {
4242
for word in buffer {
43-
nb::block!(self.try_write(word.clone()))?;
43+
nb::block!(self.write(word.clone()))?;
4444
}
4545

4646
Ok(())
4747
}
4848

49-
fn try_bflush(&mut self) -> Result<(), Self::Error> {
50-
nb::block!(self.try_flush())?;
49+
fn bflush(&mut self) -> Result<(), Self::Error> {
50+
nb::block!(self.flush())?;
5151
Ok(())
5252
}
5353
}

src/blocking/spi.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub trait Transfer<W> {
66
type Error;
77

88
/// Sends `words` to the slave. Returns the `words` received from the slave
9-
fn try_transfer<'w>(&mut self, words: &'w mut [W]) -> Result<&'w [W], Self::Error>;
9+
fn transfer<'w>(&mut self, words: &'w mut [W]) -> Result<&'w [W], Self::Error>;
1010
}
1111

1212
/// Blocking write
@@ -15,7 +15,7 @@ pub trait Write<W> {
1515
type Error;
1616

1717
/// Sends `words` to the slave, ignoring all the incoming words
18-
fn try_write(&mut self, words: &[W]) -> Result<(), Self::Error>;
18+
fn write(&mut self, words: &[W]) -> Result<(), Self::Error>;
1919
}
2020

2121
/// Blocking write (iterator version)
@@ -24,7 +24,7 @@ pub trait WriteIter<W> {
2424
type Error;
2525

2626
/// Sends `words` to the slave, ignoring all the incoming words
27-
fn try_write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
27+
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
2828
where
2929
WI: IntoIterator<Item = W>;
3030
}
@@ -42,10 +42,10 @@ pub mod transfer {
4242
{
4343
type Error = S::Error;
4444

45-
fn try_transfer<'w>(&mut self, words: &'w mut [W]) -> Result<&'w [W], S::Error> {
45+
fn transfer<'w>(&mut self, words: &'w mut [W]) -> Result<&'w [W], S::Error> {
4646
for word in words.iter_mut() {
47-
nb::block!(self.try_send(word.clone()))?;
48-
*word = nb::block!(self.try_read())?;
47+
nb::block!(self.send(word.clone()))?;
48+
*word = nb::block!(self.read())?;
4949
}
5050

5151
Ok(words)
@@ -65,10 +65,10 @@ pub mod write {
6565
{
6666
type Error = S::Error;
6767

68-
fn try_write(&mut self, words: &[W]) -> Result<(), S::Error> {
68+
fn write(&mut self, words: &[W]) -> Result<(), S::Error> {
6969
for word in words {
70-
nb::block!(self.try_send(word.clone()))?;
71-
nb::block!(self.try_read())?;
70+
nb::block!(self.send(word.clone()))?;
71+
nb::block!(self.read())?;
7272
}
7373

7474
Ok(())
@@ -89,13 +89,13 @@ pub mod write_iter {
8989
{
9090
type Error = S::Error;
9191

92-
fn try_write_iter<WI>(&mut self, words: WI) -> Result<(), S::Error>
92+
fn write_iter<WI>(&mut self, words: WI) -> Result<(), S::Error>
9393
where
9494
WI: IntoIterator<Item = W>,
9595
{
9696
for word in words.into_iter() {
97-
nb::block!(self.try_send(word.clone()))?;
98-
nb::block!(self.try_read())?;
97+
nb::block!(self.send(word.clone()))?;
98+
nb::block!(self.read())?;
9999
}
100100

101101
Ok(())
@@ -121,7 +121,7 @@ pub trait Transactional<W: 'static> {
121121
type Error;
122122

123123
/// Execute the provided transactions
124-
fn try_exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>;
124+
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>;
125125
}
126126

127127
/// Blocking transactional impl over spi::Write and spi::Transfer
@@ -139,11 +139,11 @@ pub mod transactional {
139139
{
140140
type Error = E;
141141

142-
fn try_exec<'a>(&mut self, operations: &mut [super::Operation<'a, W>]) -> Result<(), E> {
142+
fn exec<'a>(&mut self, operations: &mut [super::Operation<'a, W>]) -> Result<(), E> {
143143
for op in operations {
144144
match op {
145-
Operation::Write(w) => self.try_write(w)?,
146-
Operation::Transfer(t) => self.try_transfer(t).map(|_| ())?,
145+
Operation::Write(w) => self.write(w)?,
146+
Operation::Transfer(t) => self.transfer(t).map(|_| ())?,
147147
}
148148
}
149149

src/capture.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ use nb;
2222
/// # Capture1
2323
/// };
2424
///
25-
/// capture.try_set_resolution(1.ms()).unwrap();
25+
/// capture.set_resolution(1.ms()).unwrap();
2626
///
27-
/// let before = block!(capture.try_capture(Channel::_1)).unwrap();
28-
/// let after = block!(capture.try_capture(Channel::_1)).unwrap();
27+
/// let before = block!(capture.capture(Channel::_1)).unwrap();
28+
/// let after = block!(capture.capture(Channel::_1)).unwrap();
2929
///
3030
/// let period = after.wrapping_sub(before);
3131
///
@@ -43,11 +43,11 @@ use nb;
4343
/// # type Capture = u16;
4444
/// # type Channel = Channel;
4545
/// # type Time = MilliSeconds;
46-
/// # fn try_capture(&mut self, _: Channel) -> ::nb::Result<u16, Self::Error> { Ok(0) }
47-
/// # fn try_disable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
48-
/// # fn try_enable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
49-
/// # fn try_get_resolution(&self) -> Result<MilliSeconds, Self::Error> { unimplemented!() }
50-
/// # fn try_set_resolution<T>(&mut self, _: T) -> Result<(), Self::Error> where T: Into<MilliSeconds> { Ok(()) }
46+
/// # fn capture(&mut self, _: Channel) -> ::nb::Result<u16, Self::Error> { Ok(0) }
47+
/// # fn disable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
48+
/// # fn enable(&mut self, _: Channel) -> Result<(), Self::Error> { unimplemented!() }
49+
/// # fn get_resolution(&self) -> Result<MilliSeconds, Self::Error> { unimplemented!() }
50+
/// # fn set_resolution<T>(&mut self, _: T) -> Result<(), Self::Error> where T: Into<MilliSeconds> { Ok(()) }
5151
/// # }
5252
/// ```
5353
// unproven reason: pre-singletons API. With singletons a `CapturePin` (cf. `PwmPin`) trait seems more
@@ -78,19 +78,19 @@ pub trait Capture {
7878
///
7979
/// NOTE that you must multiply the returned value by the *resolution* of
8080
/// this `Capture` interface to get a human time unit (e.g. seconds)
81-
fn try_capture(&mut self, channel: Self::Channel) -> nb::Result<Self::Capture, Self::Error>;
81+
fn capture(&mut self, channel: Self::Channel) -> nb::Result<Self::Capture, Self::Error>;
8282

8383
/// Disables a capture `channel`
84-
fn try_disable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
84+
fn disable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
8585

8686
/// Enables a capture `channel`
87-
fn try_enable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
87+
fn enable(&mut self, channel: Self::Channel) -> Result<(), Self::Error>;
8888

8989
/// Returns the current resolution
90-
fn try_get_resolution(&self) -> Result<Self::Time, Self::Error>;
90+
fn get_resolution(&self) -> Result<Self::Time, Self::Error>;
9191

9292
/// Sets the resolution of the capture timer
93-
fn try_set_resolution<R>(&mut self, resolution: R) -> Result<(), Self::Error>
93+
fn set_resolution<R>(&mut self, resolution: R) -> Result<(), Self::Error>
9494
where
9595
R: Into<Self::Time>;
9696
}

0 commit comments

Comments
 (0)