embedded_platform/gpio/
get.rs

1//! Defines futures for getting the value off of a GPIO pin.
2use core::future;
3use core::pin;
4use core::task;
5
6/// A future which reads the value off a GPIO pin.
7#[derive(Debug)]
8#[must_use = "futures do nothing unless you `.await` or poll them"]
9pub struct Get<'a, A>
10where
11    A: super::InputPin + Unpin + ?Sized,
12{
13    pin: &'a mut A,
14}
15
16/// Creates a new [`Get`] for the provided GPIO pin.
17pub fn get<A>(pin: &mut A) -> Get<A>
18where
19    A: super::InputPin + Unpin + ?Sized,
20{
21    Get { pin }
22}
23
24impl<A> future::Future for Get<'_, A>
25where
26    A: super::InputPin + Unpin + ?Sized,
27{
28    type Output = Result<bool, A::Error>;
29
30    fn poll(mut self: pin::Pin<&mut Self>, cx: &mut task::Context<'_>) -> task::Poll<Self::Output> {
31        let this = &mut *self;
32        pin::Pin::new(&mut *this.pin).poll_get(cx)
33    }
34}