Skip to main content

ratatui_kit/element/
mod.rs

1use crate::{AnyProps, Component, ComponentHelper, ComponentHelperExt};
2mod key;
3pub use key::ElementKey;
4mod any_element;
5pub use any_element::AnyElement;
6mod element_ext;
7pub use element_ext::{ElementExt, ElementRepr};
8mod extend_with_elements;
9pub use extend_with_elements::{ExtendWithElements, extend_with_elements};
10
11#[doc(hidden)]
12pub trait ElementType {
13    type Props<'a>
14    where
15        Self: 'a;
16}
17
18#[derive(Clone)]
19pub struct Element<'a, T: ElementType + 'a> {
20    pub key: ElementKey,
21    pub props: T::Props<'a>,
22}
23
24impl<'a, T> Element<'a, T>
25where
26    T: Component + 'a,
27{
28    pub fn into_any(self) -> AnyElement<'a> {
29        self.into()
30    }
31}
32
33impl<'a, T> ElementRepr for Element<'a, T>
34where
35    T: Component,
36{
37    fn key(&self) -> &ElementKey {
38        &self.key
39    }
40
41    fn helper(&self) -> Box<dyn ComponentHelperExt> {
42        ComponentHelper::<T>::boxed()
43    }
44
45    fn props_mut(&'_ mut self) -> AnyProps<'_> {
46        AnyProps::borrowed(&mut self.props, ComponentHelper::<T>::props_type_id())
47    }
48}