embedded_menu/interaction/
programmed.rs

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::marker::PhantomData;

use crate::interaction::{InputAdapter, InputAdapterSource, InputResult, Interaction};

#[derive(Clone, Copy)]
pub struct Programmed;

impl<R> InputAdapterSource<R> for Programmed {
    type InputAdapter = ProgrammedAdapter<R>;

    fn adapter(&self) -> Self::InputAdapter {
        ProgrammedAdapter {
            _marker: PhantomData,
        }
    }
}

pub struct ProgrammedAdapter<R> {
    _marker: PhantomData<R>,
}

impl<R> Clone for ProgrammedAdapter<R> {
    fn clone(&self) -> Self {
        *self
    }
}

impl<R> Copy for ProgrammedAdapter<R> {}

impl<R> InputAdapter for ProgrammedAdapter<R> {
    type Input = Interaction<R>;
    type Value = R;
    type State = ();

    fn handle_input(
        &self,
        _state: &mut Self::State,
        action: Self::Input,
    ) -> InputResult<Self::Value> {
        InputResult::from(action)
    }
}