recompose_core/
keyed.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
use crate::{dyn_compose::DynCompose, Compose, Key, Scope};

#[derive(Clone)]
pub struct Keyed {
    key: usize,
    compose: DynCompose,
}

impl Keyed {
    pub fn new<C: Compose + 'static>(key: usize, compose: C) -> Self {
        Self {
            key,
            compose: DynCompose::new(compose),
        }
    }
}

impl Compose for Keyed {
    fn compose<'a>(&self, cx: &mut Scope) -> impl Compose + 'a {
        self.compose.compose(cx)
    }

    fn decompose(&self, cx: &mut Scope) {
        self.compose.compose(cx);
    }

    fn ignore_children(&self) -> bool {
        self.compose.ignore_children()
    }
}

impl Key for Keyed {
    fn key(&self) -> usize {
        self.key
    }
}