embedded_hal_mock/lib.rs
1//! This is a collection of types that implement the embedded-hal traits.
2//!
3//! The implementations never access real hardware. Instead, the hardware is
4//! mocked or no-op implementations are used.
5//!
6//! The goal of the crate is to be able to test drivers in CI without having
7//! access to hardware.
8//!
9//! ## Usage
10//!
11//! The general approach for testing drivers using mocks:
12//!
13//! 1. Define the expectations: A list of transactions (e.g. a read or write
14//! operation) that you expect the driver-under-test to invoke on the mocked
15//! hardware
16//! 2. Instantiate the mock with the expectations
17//! 3. Run the test code
18//! 4. At the end of the test code, call the `.done()` method on the mock to
19//! ensure that all expectations were met
20//!
21//! For more information, see module-level docs.
22//!
23//! **Note:** Mocks contain an `Arc` internally and can be cloned freely. This
24//! means you can clone a mock before passing it to the driver, and then call
25//! `.done()` on the second mock instance without having to reclaim the first
26//! instance from the driver.
27//!
28//! ## embedded_hal Version Support
29//!
30//! This crate supports both version 0.x and version 1.x of embedded-hal. By
31//! default only support for version 0.x is enabled. To enable support for
32//! version 1.x, use the `eh1` feature.
33//!
34//! ## Cargo Features
35//!
36//! There are currently the following cargo features:
37//!
38//! - `eh0`: Provide module [`eh0`] that mocks embedded-hal version 0.x
39//! (enabled by default)
40//! - `eh1`: Provide module [`eh1`] that mocks embedded-hal version 1.x
41//! (enabled by default)
42//! - `embedded-time`: Enable the [`eh0::timer`] module (enabled by default)
43//! - `embedded-hal-async`: Provide mocks for embedded-hal-async in [`eh1`]
44#![cfg_attr(docsrs, feature(doc_cfg), feature(doc_auto_cfg))]
45#![deny(missing_docs)]
46
47pub mod common;
48#[cfg(feature = "eh0")]
49pub mod eh0;
50#[cfg(feature = "eh1")]
51pub mod eh1;