Skip to main content

ocpp_client/runtime/
tokio.rs

1//! tokio-backed `Executor`/`Timer` impls, used by `connect_1_6`/`connect_2_0_1` and the
2//! crate's own tests. Gated behind the `tokio-runtime` feature.
3
4use crate::runtime::{Executor, Timer};
5use alloc::boxed::Box;
6use core::future::Future;
7use core::pin::Pin;
8use core::time::Duration;
9
10/// [`Executor`] impl that spawns onto the ambient tokio runtime via `tokio::spawn`.
11#[derive(Debug, Clone, Copy, Default)]
12pub struct TokioExecutor;
13
14impl Executor for TokioExecutor {
15    fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>) {
16        tokio::spawn(future);
17    }
18}
19
20/// [`Timer`] impl backed by `tokio::time::sleep`.
21#[derive(Debug, Clone, Copy, Default)]
22pub struct TokioTimer;
23
24impl Timer for TokioTimer {
25    fn delay<'a>(&'a self, duration: Duration) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
26        Box::pin(tokio::time::sleep(duration))
27    }
28}