pub struct MockCanBus { /* private fields */ }Expand description
Single-process mock CAN bus.
Construct via MockCanBus::new for a self-loopback (frames you send come
straight back from drain_inbound_nonblocking), or via
MockCanBus::pair for an A↔B loopback (frames sent on A appear on B’s
inbound and vice-versa).
Implementations§
Source§impl MockCanBus
impl MockCanBus
Sourcepub fn new_fd(name: impl Into<String>) -> Self
pub fn new_fd(name: impl Into<String>) -> Self
FD-capability mock with self-loopback — accepts and loops back FD frames so the FD send/receive path is testable without an FD-capable interface.
Sourcepub fn with_capabilities(name: impl Into<String>, caps: BusCapabilities) -> Self
pub fn with_capabilities(name: impl Into<String>, caps: BusCapabilities) -> Self
Mock with explicit capabilities (tests that need FD-flagged behavior).
Sourcepub fn pair(
name_a: impl Into<String>,
name_b: impl Into<String>,
) -> (Self, Self)
pub fn pair( name_a: impl Into<String>, name_b: impl Into<String>, ) -> (Self, Self)
Pair of mocks that loopback to each other (a.send(f) → b.drain sees f).
Sourcepub fn sent_frames(&self) -> Vec<CanFrame>
pub fn sent_frames(&self) -> Vec<CanFrame>
Snapshot of every frame this bus has transmitted via send.
Sourcepub fn recorded_calls(&self) -> Vec<MockRecordedCall>
pub fn recorded_calls(&self) -> Vec<MockRecordedCall>
Snapshot of the call sequence for assertion of “sends never read”.
Sourcepub fn inject_frame(&self, frame: CanFrame)
pub fn inject_frame(&self, frame: CanFrame)
Push a frame onto this bus’s inbound queue (as if a peer wrote it).
Trait Implementations§
Source§impl CanBus for MockCanBus
impl CanBus for MockCanBus
Source§fn capabilities(&self) -> BusCapabilities
fn capabilities(&self) -> BusCapabilities
Runtime capabilities of this bus (FD support, max payload length).
Source§fn send(&mut self, frame: &CanFrame) -> Result<(), TransportError>
fn send(&mut self, frame: &CanFrame) -> Result<(), TransportError>
Send a single frame. Must not call
read or poll internally.Source§fn drain_inbound_nonblocking(&mut self) -> Result<Vec<CanFrame>, TransportError>
fn drain_inbound_nonblocking(&mut self) -> Result<Vec<CanFrame>, TransportError>
Drain every frame currently in the receive queue and return them in
arrival order. Returns
Ok(vec![]) immediately if the queue is empty.Source§impl Clone for MockCanBus
impl Clone for MockCanBus
Source§fn clone(&self) -> MockCanBus
fn clone(&self) -> MockCanBus
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MockCanBus
impl RefUnwindSafe for MockCanBus
impl Send for MockCanBus
impl Sync for MockCanBus
impl Unpin for MockCanBus
impl UnsafeUnpin for MockCanBus
impl UnwindSafe for MockCanBus
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