Skip to content

Commit 5aa6d09

Browse files
committed
Auto merge of #20 - hannobraun:mut-self, r=japaric
Change traits to take `&mut self`, where appropriate This pull request supersedes #16, which seems stalled. It is based on #19. Only the last two commits are actually relevant to this pull request itself. I suggest merging #19 first, then I can rebase this one.
2 parents dbafdc7 + 5e2c733 commit 5aa6d09

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

src/lib.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@
8585
//! fn get_timeout(&self) -> Self::Time;
8686
//!
8787
//! /// Pauses the timer
88-
//! fn pause(&self);
88+
//! fn pause(&mut self);
8989
//!
9090
//! /// Restarts the timer count
91-
//! fn restart(&self);
91+
//! fn restart(&mut self);
9292
//!
9393
//! /// Resumes the timer count
94-
//! fn resume(&self);
94+
//! fn resume(&mut self);
9595
//!
9696
//! /// Sets a new timeout
97-
//! fn set_timeout<T>(&self, ticks: T) where T: Into<Self::Time>;
97+
//! fn set_timeout<T>(&mut self, ticks: T) where T: Into<Self::Time>;
9898
//!
9999
//! /// "waits" until the timer times out
100100
//! fn wait(&self) -> nb::Result<(), !>;
@@ -146,7 +146,7 @@
146146
//! {
147147
//! type Error = Error;
148148
//!
149-
//! fn read(&self) -> nb::Result<u8, Error> {
149+
//! fn read(&mut self) -> nb::Result<u8, Error> {
150150
//! // read the status register
151151
//! let sr = self.0.sr.read();
152152
//!
@@ -172,7 +172,7 @@
172172
//! {
173173
//! type Error = Error;
174174
//!
175-
//! fn write(&self, byte: u8) -> nb::Result<(), Error> {
175+
//! fn write(&mut self, byte: u8) -> nb::Result<(), Error> {
176176
//! // Very similar to the above implementation
177177
//! Ok(())
178178
//! }
@@ -203,7 +203,7 @@
203203
//! impl hal::serial::Read<u8> for Serial1 {
204204
//! type Error = !;
205205
//!
206-
//! fn read(&self) -> Result<u8, nb::Error<Self::Error>> {
206+
//! fn read(&mut self) -> Result<u8, nb::Error<Self::Error>> {
207207
//! hal::serial::Read::read(&Serial(&*USART1.lock()))
208208
//! }
209209
//! }
@@ -419,7 +419,7 @@
419419
//!
420420
//! use hal::prelude::*;
421421
//!
422-
//! fn write_all<S>(serial: &S, buffer: &[u8]) -> Result<(), S::Error>
422+
//! fn write_all<S>(serial: &mut S, buffer: &[u8]) -> Result<(), S::Error>
423423
//! where
424424
//! S: hal::serial::Write<u8>
425425
//! {
@@ -446,8 +446,8 @@
446446
//! }
447447
//!
448448
//! fn read_with_timeout<S, T>(
449-
//! serial: &S,
450-
//! timer: &T,
449+
//! serial: &mut S,
450+
//! timer: &mut T,
451451
//! timeout: T::Time,
452452
//! ) -> Result<u8, Error<S::Error>>
453453
//! where
@@ -519,7 +519,7 @@
519519
//!
520520
//! use hal::prelude::*;
521521
//!
522-
//! fn flush<S>(serial: &S, cb: &mut CircularBuffer) -> Result<(), S::Error>
522+
//! fn flush<S>(serial: &mut S, cb: &mut CircularBuffer) -> Result<(), S::Error>
523523
//! where
524524
//! S: hal::serial::Write<u8>,
525525
//! {
@@ -565,7 +565,7 @@
565565
//! let serial = SERIAL.lock();
566566
//! let buffer = BUFFER.lock();
567567
//!
568-
//! flush(&serial, &mut buffer).unwrap();
568+
//! flush(&mut serial, &mut buffer).unwrap();
569569
//! }
570570
//! ```
571571
//!
@@ -660,21 +660,21 @@ pub trait Capture {
660660
/// NOTE that you must multiply the returned value by the *resolution* of
661661
/// this `Capture` interface to get a human time unit (e.g. seconds)
662662
fn capture(
663-
&self,
663+
&mut self,
664664
channel: Self::Channel,
665665
) -> nb::Result<Self::Capture, Self::Error>;
666666

667667
/// Disables a capture `channel`
668-
fn disable(&self, channel: Self::Channel);
668+
fn disable(&mut self, channel: Self::Channel);
669669

670670
/// Enables a capture `channel`
671-
fn enable(&self, channel: Self::Channel);
671+
fn enable(&mut self, channel: Self::Channel);
672672

673673
/// Returns the current resolution
674674
fn get_resolution(&self) -> Self::Time;
675675

676676
/// Sets the resolution of the capture timer
677-
fn set_resolution<R>(&self, resolution: R)
677+
fn set_resolution<R>(&mut self, resolution: R)
678678
where
679679
R: Into<Self::Time>;
680680
}
@@ -715,10 +715,10 @@ pub trait Pwm {
715715
type Duty;
716716

717717
/// Disables a PWM `channel`
718-
fn disable(&self, channel: Self::Channel);
718+
fn disable(&mut self, channel: Self::Channel);
719719

720720
/// Enables a PWM `channel`
721-
fn enable(&self, channel: Self::Channel);
721+
fn enable(&mut self, channel: Self::Channel);
722722

723723
/// Returns the current PWM period
724724
fn get_period(&self) -> Self::Time;
@@ -730,10 +730,10 @@ pub trait Pwm {
730730
fn get_max_duty(&self) -> Self::Duty;
731731

732732
/// Sets a new duty cycle
733-
fn set_duty(&self, channel: Self::Channel, duty: Self::Duty);
733+
fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty);
734734

735735
/// Sets a new PWM period
736-
fn set_period<P>(&self, period: P)
736+
fn set_period<P>(&mut self, period: P)
737737
where
738738
P: Into<Self::Time>;
739739
}
@@ -805,10 +805,10 @@ pub trait Spi<Word> {
805805
///
806806
/// **NOTE** A word must be sent to the slave before attempting to call this
807807
/// method.
808-
fn read(&self) -> nb::Result<Word, Self::Error>;
808+
fn read(&mut self) -> nb::Result<Word, Self::Error>;
809809

810810
/// Sends a word to the slave
811-
fn send(&self, word: Word) -> nb::Result<(), Self::Error>;
811+
fn send(&mut self, word: Word) -> nb::Result<(), Self::Error>;
812812
}
813813

814814
/// Timer used for timeouts
@@ -837,16 +837,16 @@ pub trait Timer {
837837
fn get_timeout(&self) -> Self::Time;
838838

839839
/// Pauses the timer
840-
fn pause(&self);
840+
fn pause(&mut self);
841841

842842
/// Restarts the timer count to zero
843-
fn restart(&self);
843+
fn restart(&mut self);
844844

845845
/// Resumes the timer count
846-
fn resume(&self);
846+
fn resume(&mut self);
847847

848848
/// Sets a new timeout
849-
fn set_timeout<T>(&self, timeout: T)
849+
fn set_timeout<T>(&mut self, timeout: T)
850850
where
851851
T: Into<Self::Time>;
852852

src/serial.rs

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

1818
/// Reads a single word from the serial interface
19-
fn read(&self) -> nb::Result<Word, Self::Error>;
19+
fn read(&mut self) -> nb::Result<Word, Self::Error>;
2020
}
2121

2222
/// Write half of a serial interface
@@ -25,5 +25,5 @@ pub trait Write<Word> {
2525
type Error;
2626

2727
/// Writes a single word to the serial interface
28-
fn write(&self, word: Word) -> nb::Result<(), Self::Error>;
28+
fn write(&mut self, word: Word) -> nb::Result<(), Self::Error>;
2929
}

0 commit comments

Comments
 (0)