1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use core::future;
use core::pin;
use core::task;
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Initialize<A, SDA, SCL>
where
A: super::I2cBusMapping<SDA, SCL> + Unpin,
SDA: Unpin,
SCL: Unpin,
{
mapping: A,
sda: SDA,
scl: SCL,
}
pub fn initialize<A, SDA, SCL>(mapping: A, sda: SDA, scl: SCL) -> Initialize<A, SDA, SCL>
where
A: super::I2cBusMapping<SDA, SCL> + Unpin,
SDA: Unpin,
SCL: Unpin,
{
Initialize { mapping, sda, scl }
}
impl<A, SDA, SCL> future::Future for Initialize<A, SDA, SCL>
where
A: super::I2cBusMapping<SDA, SCL> + Unpin,
SDA: Unpin,
SCL: Unpin,
{
type Output = Result<A::Bus, A::Error>;
fn poll(mut self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
let this = &mut *self;
pin::Pin::new(&mut this.mapping).poll_initialize(cx, &mut this.sda, &mut this.scl)
}
}