Skip to content

Commit a4fe991

Browse files
committed
Require all SPI and Serial word types to be Copy
1 parent f3c502a commit a4fe991

File tree

6 files changed

+23
-22
lines changed

6 files changed

+23
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111

1212
- Use `u8` as default SPI as Serial Word type
13+
- Require all SPI and Serial word types to be `Copy`.
1314

1415
### Added
1516
- Added `Can` Controller Area Network traits.

src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::fmt::{Result, Write};
66
impl<Word, Error: crate::serial::Error> Write
77
for dyn crate::serial::nb::Write<Word, Error = Error> + '_
88
where
9-
Word: From<u8>,
9+
Word: Copy + From<u8>,
1010
{
1111
fn write_str(&mut self, s: &str) -> Result {
1212
let _ = s

src/serial/blocking.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Blocking serial API
22
33
/// Write half of a serial interface (blocking variant)
4-
pub trait Write<Word = u8> {
4+
pub trait Write<Word: Copy = u8> {
55
/// The type of error that can occur when writing
66
type Error: crate::serial::Error;
77

@@ -19,7 +19,7 @@ pub trait Write<Word = u8> {
1919
fn flush(&mut self) -> Result<(), Self::Error>;
2020
}
2121

22-
impl<T: Write<Word>, Word> Write<Word> for &mut T {
22+
impl<T: Write<Word>, Word: Copy> Write<Word> for &mut T {
2323
type Error = T::Error;
2424

2525
fn write(&mut self, buffer: &[Word]) -> Result<(), Self::Error> {

src/serial/nb.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
///
55
/// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
66
/// This can be encoded in this trait via the `Word` type parameter.
7-
pub trait Read<Word = u8> {
7+
pub trait Read<Word: Copy = u8> {
88
/// Read error
99
type Error: crate::serial::Error;
1010

1111
/// Reads a single word from the serial interface
1212
fn read(&mut self) -> nb::Result<Word, Self::Error>;
1313
}
1414

15-
impl<T: Read<Word>, Word> Read<Word> for &mut T {
15+
impl<T: Read<Word>, Word: Copy> Read<Word> for &mut T {
1616
type Error = T::Error;
1717

1818
fn read(&mut self) -> nb::Result<Word, Self::Error> {
@@ -21,7 +21,7 @@ impl<T: Read<Word>, Word> Read<Word> for &mut T {
2121
}
2222

2323
/// Write half of a serial interface
24-
pub trait Write<Word = u8> {
24+
pub trait Write<Word: Copy = u8> {
2525
/// Write error
2626
type Error: crate::serial::Error;
2727

@@ -32,7 +32,7 @@ pub trait Write<Word = u8> {
3232
fn flush(&mut self) -> nb::Result<(), Self::Error>;
3333
}
3434

35-
impl<T: Write<Word>, Word> Write<Word> for &mut T {
35+
impl<T: Write<Word>, Word: Copy> Write<Word> for &mut T {
3636
type Error = T::Error;
3737

3838
fn write(&mut self, word: Word) -> nb::Result<(), Self::Error> {

src/spi/blocking.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Blocking SPI API
22
33
/// Blocking transfer with separate buffers
4-
pub trait Transfer<W = u8> {
4+
pub trait Transfer<W: Copy = u8> {
55
/// Error type
66
type Error: crate::spi::Error;
77

@@ -16,7 +16,7 @@ pub trait Transfer<W = u8> {
1616
fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error>;
1717
}
1818

19-
impl<T: Transfer<W>, W> Transfer<W> for &mut T {
19+
impl<T: Transfer<W>, W: Copy> Transfer<W> for &mut T {
2020
type Error = T::Error;
2121

2222
fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> {
@@ -25,7 +25,7 @@ impl<T: Transfer<W>, W> Transfer<W> for &mut T {
2525
}
2626

2727
/// Blocking transfer with single buffer (in-place)
28-
pub trait TransferInplace<W = u8> {
28+
pub trait TransferInplace<W: Copy = u8> {
2929
/// Error type
3030
type Error: crate::spi::Error;
3131

@@ -35,7 +35,7 @@ pub trait TransferInplace<W = u8> {
3535
fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
3636
}
3737

38-
impl<T: TransferInplace<W>, W> TransferInplace<W> for &mut T {
38+
impl<T: TransferInplace<W>, W: Copy> TransferInplace<W> for &mut T {
3939
type Error = T::Error;
4040

4141
fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
@@ -44,7 +44,7 @@ impl<T: TransferInplace<W>, W> TransferInplace<W> for &mut T {
4444
}
4545

4646
/// Blocking read
47-
pub trait Read<W = u8> {
47+
pub trait Read<W: Copy = u8> {
4848
/// Error type
4949
type Error: crate::spi::Error;
5050

@@ -55,7 +55,7 @@ pub trait Read<W = u8> {
5555
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>;
5656
}
5757

58-
impl<T: Read<W>, W> Read<W> for &mut T {
58+
impl<T: Read<W>, W: Copy> Read<W> for &mut T {
5959
type Error = T::Error;
6060

6161
fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> {
@@ -64,15 +64,15 @@ impl<T: Read<W>, W> Read<W> for &mut T {
6464
}
6565

6666
/// Blocking write
67-
pub trait Write<W = u8> {
67+
pub trait Write<W: Copy = u8> {
6868
/// Error type
6969
type Error: crate::spi::Error;
7070

7171
/// Writes `words` to the slave, ignoring all the incoming words
7272
fn write(&mut self, words: &[W]) -> Result<(), Self::Error>;
7373
}
7474

75-
impl<T: Write<W>, W> Write<W> for &mut T {
75+
impl<T: Write<W>, W: Copy> Write<W> for &mut T {
7676
type Error = T::Error;
7777

7878
fn write(&mut self, words: &[W]) -> Result<(), Self::Error> {
@@ -81,7 +81,7 @@ impl<T: Write<W>, W> Write<W> for &mut T {
8181
}
8282

8383
/// Blocking write (iterator version)
84-
pub trait WriteIter<W = u8> {
84+
pub trait WriteIter<W: Copy = u8> {
8585
/// Error type
8686
type Error: crate::spi::Error;
8787

@@ -91,7 +91,7 @@ pub trait WriteIter<W = u8> {
9191
WI: IntoIterator<Item = W>;
9292
}
9393

94-
impl<T: WriteIter<W>, W> WriteIter<W> for &mut T {
94+
impl<T: WriteIter<W>, W: Copy> WriteIter<W> for &mut T {
9595
type Error = T::Error;
9696

9797
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
@@ -106,7 +106,7 @@ impl<T: WriteIter<W>, W> WriteIter<W> for &mut T {
106106
///
107107
/// This allows composition of SPI operations into a single bus transaction
108108
#[derive(Debug, PartialEq)]
109-
pub enum Operation<'a, W: 'static = u8> {
109+
pub enum Operation<'a, W: Copy = u8> {
110110
/// Read data into the provided buffer.
111111
Read(&'a mut [W]),
112112
/// Write data from the provided buffer, discarding read data
@@ -119,15 +119,15 @@ pub enum Operation<'a, W: 'static = u8> {
119119

120120
/// Transactional trait allows multiple actions to be executed
121121
/// as part of a single SPI transaction
122-
pub trait Transactional<W: 'static = u8> {
122+
pub trait Transactional<W: Copy = u8> {
123123
/// Associated error type
124124
type Error: crate::spi::Error;
125125

126126
/// Execute the provided transactions
127127
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>;
128128
}
129129

130-
impl<T: Transactional<W>, W: 'static> Transactional<W> for &mut T {
130+
impl<T: Transactional<W>, W: Copy> Transactional<W> for &mut T {
131131
type Error = T::Error;
132132

133133
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error> {

src/spi/nb.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
///
1717
/// - Some SPIs can work with 8-bit *and* 16-bit words. You can overload this trait with different
1818
/// `Word` types to allow operation in both modes.
19-
pub trait FullDuplex<Word = u8> {
19+
pub trait FullDuplex<Word: Copy = u8> {
2020
/// An enumeration of SPI errors
2121
type Error: crate::spi::Error;
2222

@@ -30,7 +30,7 @@ pub trait FullDuplex<Word = u8> {
3030
fn write(&mut self, word: Word) -> nb::Result<(), Self::Error>;
3131
}
3232

33-
impl<T: FullDuplex<Word>, Word> FullDuplex<Word> for &mut T {
33+
impl<T: FullDuplex<Word>, Word: Copy> FullDuplex<Word> for &mut T {
3434
type Error = T::Error;
3535

3636
fn read(&mut self) -> nb::Result<Word, Self::Error> {

0 commit comments

Comments
 (0)