Skip to main content

MockUsbTransfer

Struct MockUsbTransfer 

Source
pub struct MockUsbTransfer { /* private fields */ }
Expand description

In-memory mock of UsbTransfer for unit tests.

Pre-load expected read responses per endpoint, then execute protocol logic. After the test, inspect captured writes to verify correctness.

§Thread safety

State lives behind a Mutex, so the Send + Sync that UsbTransfer requires is derived rather than asserted. The mock used to hold RefCell and claim the bounds with unsafe impl, which was unsound: RefCell’s borrow flag is not atomic, so two threads sharing one mock could hold overlapping borrow_mut()s and alias the same &mut.

Implementations§

Source§

impl MockUsbTransfer

Source

pub fn new() -> Self

Create an empty mock with no pre-loaded responses.

Source

pub fn enqueue_read(&self, endpoint: u8, data: Vec<u8>)

Enqueue a response that will be returned by the next bulk_read on the given endpoint.

Source

pub fn take_writes(&self, endpoint: u8) -> Vec<Vec<u8>>

Return all captured write payloads for the given endpoint.

Trait Implementations§

Source§

impl Default for MockUsbTransfer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl UsbTransfer for MockUsbTransfer

Source§

fn bulk_write( &self, endpoint: u8, data: &[u8], _timeout: Duration, ) -> Result<usize, U3vError>

Write data to the bulk OUT endpoint. Returns bytes written.
Source§

fn bulk_read( &self, endpoint: u8, buf: &mut [u8], _timeout: Duration, ) -> Result<usize, U3vError>

Read up to buf.len() bytes from the bulk IN endpoint. Returns the number of bytes actually read.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more