Struct cansat_test_utils::mock::Serial
source · pub struct Serial<I> {
pub tx_data: I,
pub rx_data: Vec<u8>,
}
Expand description
Mock type implementing embedded_hal::serial
traits.
Fields§
§tx_data: I
§rx_data: Vec<u8>
Implementations§
Trait Implementations§
source§impl<I: ExactSizeIterator<Item = u8>> Read<u8> for Serial<I>
impl<I: ExactSizeIterator<Item = u8>> Read<u8> for Serial<I>
source§fn read(&mut self) -> Result<u8, Self::Error>
fn read(&mut self) -> Result<u8, Self::Error>
Reads a single byte from the serial.
Examples
use cansat_test_utils::mock::Serial;
use embedded_hal::{nb, serial::nb::Read};
let mut serial = Serial::new([0x00, 0x01]);
assert_eq!(serial.read(), Ok(0x00));
assert_eq!(serial.read(), Ok(0x01));
assert_eq!(serial.read(), Err(nb::Error::WouldBlock));
source§impl<I> Write<u8> for Serial<I>
impl<I> Write<u8> for Serial<I>
source§fn write(&mut self, word: u8) -> Result<(), Self::Error>
fn write(&mut self, word: u8) -> Result<(), Self::Error>
Write a single byte to the serial.
Examples
use cansat_test_utils::mock::Serial;
use embedded_hal::{nb, serial::nb::Write};
let mut serial = Serial::new(Vec::<u8>::new());
assert_eq!(serial.write(0x12), Ok(()));
assert_eq!(serial.rx_data, &[0x12]);
Auto Trait Implementations§
impl<I> RefUnwindSafe for Serial<I>where I: RefUnwindSafe,
impl<I> Send for Serial<I>where I: Send,
impl<I> Sync for Serial<I>where I: Sync,
impl<I> Unpin for Serial<I>where I: Unpin,
impl<I> UnwindSafe for Serial<I>where I: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more