diff --git a/CHANGELOG.md b/CHANGELOG.md index 656efa373..177bf3908 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - Use `u8` as default SPI as Serial Word type - The Minimum Supported Rust Version (MSRV) is now 1.46.0 +- Require all SPI and Serial word types to be `Copy`. ### Added - Added `Can` Controller Area Network traits. diff --git a/src/fmt.rs b/src/fmt.rs index 8d5c141ea..7b89f71e4 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -6,7 +6,7 @@ use core::fmt::{Result, Write}; impl Write for dyn crate::serial::nb::Write + '_ where - Word: From, + Word: Copy + From, { fn write_str(&mut self, s: &str) -> Result { let _ = s diff --git a/src/serial/blocking.rs b/src/serial/blocking.rs index 7b9c8a9d2..7b2b8d752 100644 --- a/src/serial/blocking.rs +++ b/src/serial/blocking.rs @@ -1,7 +1,7 @@ //! Blocking serial API /// Write half of a serial interface (blocking variant) -pub trait Write { +pub trait Write { /// The type of error that can occur when writing type Error: crate::serial::Error; @@ -19,7 +19,7 @@ pub trait Write { fn flush(&mut self) -> Result<(), Self::Error>; } -impl, Word> Write for &mut T { +impl, Word: Copy> Write for &mut T { type Error = T::Error; fn write(&mut self, buffer: &[Word]) -> Result<(), Self::Error> { diff --git a/src/serial/nb.rs b/src/serial/nb.rs index bb0467d66..df40f2bb5 100644 --- a/src/serial/nb.rs +++ b/src/serial/nb.rs @@ -4,7 +4,7 @@ /// /// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.); /// This can be encoded in this trait via the `Word` type parameter. -pub trait Read { +pub trait Read { /// Read error type Error: crate::serial::Error; @@ -12,7 +12,7 @@ pub trait Read { fn read(&mut self) -> nb::Result; } -impl, Word> Read for &mut T { +impl, Word: Copy> Read for &mut T { type Error = T::Error; fn read(&mut self) -> nb::Result { @@ -21,7 +21,7 @@ impl, Word> Read for &mut T { } /// Write half of a serial interface -pub trait Write { +pub trait Write { /// Write error type Error: crate::serial::Error; @@ -32,7 +32,7 @@ pub trait Write { fn flush(&mut self) -> nb::Result<(), Self::Error>; } -impl, Word> Write for &mut T { +impl, Word: Copy> Write for &mut T { type Error = T::Error; fn write(&mut self, word: Word) -> nb::Result<(), Self::Error> { diff --git a/src/spi/blocking.rs b/src/spi/blocking.rs index cde2baae9..d7f215605 100644 --- a/src/spi/blocking.rs +++ b/src/spi/blocking.rs @@ -1,7 +1,7 @@ //! Blocking SPI API /// Blocking transfer with separate buffers -pub trait Transfer { +pub trait Transfer { /// Error type type Error: crate::spi::Error; @@ -16,7 +16,7 @@ pub trait Transfer { fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error>; } -impl, W> Transfer for &mut T { +impl, W: Copy> Transfer for &mut T { type Error = T::Error; fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { @@ -25,7 +25,7 @@ impl, W> Transfer for &mut T { } /// Blocking transfer with single buffer (in-place) -pub trait TransferInplace { +pub trait TransferInplace { /// Error type type Error: crate::spi::Error; @@ -35,7 +35,7 @@ pub trait TransferInplace { fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error>; } -impl, W> TransferInplace for &mut T { +impl, W: Copy> TransferInplace for &mut T { type Error = T::Error; fn transfer_inplace(&mut self, words: &mut [W]) -> Result<(), Self::Error> { @@ -44,7 +44,7 @@ impl, W> TransferInplace for &mut T { } /// Blocking read -pub trait Read { +pub trait Read { /// Error type type Error: crate::spi::Error; @@ -55,7 +55,7 @@ pub trait Read { fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error>; } -impl, W> Read for &mut T { +impl, W: Copy> Read for &mut T { type Error = T::Error; fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { @@ -64,7 +64,7 @@ impl, W> Read for &mut T { } /// Blocking write -pub trait Write { +pub trait Write { /// Error type type Error: crate::spi::Error; @@ -72,7 +72,7 @@ pub trait Write { fn write(&mut self, words: &[W]) -> Result<(), Self::Error>; } -impl, W> Write for &mut T { +impl, W: Copy> Write for &mut T { type Error = T::Error; fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { @@ -81,7 +81,7 @@ impl, W> Write for &mut T { } /// Blocking write (iterator version) -pub trait WriteIter { +pub trait WriteIter { /// Error type type Error: crate::spi::Error; @@ -91,7 +91,7 @@ pub trait WriteIter { WI: IntoIterator; } -impl, W> WriteIter for &mut T { +impl, W: Copy> WriteIter for &mut T { type Error = T::Error; fn write_iter(&mut self, words: WI) -> Result<(), Self::Error> @@ -106,7 +106,7 @@ impl, W> WriteIter for &mut T { /// /// This allows composition of SPI operations into a single bus transaction #[derive(Debug, PartialEq)] -pub enum Operation<'a, W: 'static = u8> { +pub enum Operation<'a, W: 'static + Copy = u8> { /// Read data into the provided buffer. Read(&'a mut [W]), /// Write data from the provided buffer, discarding read data @@ -119,7 +119,7 @@ pub enum Operation<'a, W: 'static = u8> { /// Transactional trait allows multiple actions to be executed /// as part of a single SPI transaction -pub trait Transactional { +pub trait Transactional { /// Associated error type type Error: crate::spi::Error; @@ -127,7 +127,7 @@ pub trait Transactional { fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>; } -impl, W: 'static> Transactional for &mut T { +impl, W: 'static + Copy> Transactional for &mut T { type Error = T::Error; fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error> { diff --git a/src/spi/nb.rs b/src/spi/nb.rs index 6d540a762..03778db99 100644 --- a/src/spi/nb.rs +++ b/src/spi/nb.rs @@ -16,7 +16,7 @@ /// /// - Some SPIs can work with 8-bit *and* 16-bit words. You can overload this trait with different /// `Word` types to allow operation in both modes. -pub trait FullDuplex { +pub trait FullDuplex { /// An enumeration of SPI errors type Error: crate::spi::Error; @@ -30,7 +30,7 @@ pub trait FullDuplex { fn write(&mut self, word: Word) -> nb::Result<(), Self::Error>; } -impl, Word> FullDuplex for &mut T { +impl, Word: Copy> FullDuplex for &mut T { type Error = T::Error; fn read(&mut self) -> nb::Result {