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
impl MockUsbTransfer
Sourcepub fn enqueue_read(&self, endpoint: u8, data: Vec<u8>)
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.
Trait Implementations§
Source§impl Default for MockUsbTransfer
impl Default for MockUsbTransfer
Source§impl UsbTransfer for MockUsbTransfer
impl UsbTransfer for MockUsbTransfer
Auto Trait Implementations§
impl !Freeze for MockUsbTransfer
impl RefUnwindSafe for MockUsbTransfer
impl Send for MockUsbTransfer
impl Sync for MockUsbTransfer
impl Unpin for MockUsbTransfer
impl UnsafeUnpin for MockUsbTransfer
impl UnwindSafe for MockUsbTransfer
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