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§

source§

impl<I> Serial<I>

source

pub fn new(data: impl IntoIterator<IntoIter = I>) -> Self

Creates an instance of serial mock that will output data byte by byte.

Examples
pub use cansat_test_utils::mock::Serial;

let _ = Serial::new(b"my_data");
let _ = Serial::new(vec![0x00, 0x01]);

Trait Implementations§

source§

impl<I> ErrorType for Serial<I>

§

type Error = Infallible

Error type
source§

impl<I: ExactSizeIterator<Item = u8>> Read<u8> for Serial<I>

source§

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>

source§

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]);
source§

fn flush(&mut self) -> Result<(), Self::Error>

Does nothing

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.