ratatui_kit/element/
mod.rs1use 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
11pub trait ElementType {
12 type Props<'a>
13 where
14 Self: 'a;
15}
16
17#[derive(Clone)]
18pub struct Element<'a, T: ElementType + 'a> {
19 pub key: ElementKey,
20 pub props: T::Props<'a>,
21}
22
23impl<'a, T> Element<'a, T>
24where
25 T: Component + 'a,
26{
27 pub fn into_any(self) -> AnyElement<'a> {
28 self.into()
29 }
30}
31
32impl<'a, T> ElementRepr for Element<'a, T>
33where
34 T: Component,
35{
36 fn key(&self) -> &ElementKey {
37 &self.key
38 }
39
40 fn helper(&self) -> Box<dyn ComponentHelperExt> {
41 ComponentHelper::<T>::boxed()
42 }
43
44 fn props_mut(&'_ mut self) -> AnyProps<'_> {
45 AnyProps::borrowed(&mut self.props, ComponentHelper::<T>::props_type_id())
46 }
47}