pub struct MockDriver(/* private fields */);Expand description
A mock driver that can be manually advanced.
This is useful for testing code that works with Instant and Duration.
This driver can also be used to test runtime functionality, such as timers, delays, etc.
§Example
ⓘ
fn has_a_second_passed(reference: Instant) -> bool {
Instant::now().duration_since(reference) >= Duration::from_secs(1)
}
fn test_second_passed() {
let driver = embassy_time::MockDriver::get();
let reference = Instant::now();
assert_eq!(false, has_a_second_passed(reference));
driver.advance(Duration::from_secs(1));
assert_eq!(true, has_a_second_passed(reference));
}Implementations§
Source§impl MockDriver
impl MockDriver
Sourcepub fn get() -> &'static MockDriver
pub fn get() -> &'static MockDriver
Gets a reference to the global mock driver.
Trait Implementations§
Source§impl Debug for MockDriver
impl Debug for MockDriver
Auto Trait Implementations§
impl !Freeze for MockDriver
impl !RefUnwindSafe for MockDriver
impl !UnwindSafe for MockDriver
impl Send for MockDriver
impl Sync for MockDriver
impl Unpin for MockDriver
impl UnsafeUnpin for MockDriver
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