topcoat_view/component.rs
1use topcoat_core::{context::Cx, error::Result};
2
3use crate::{Props, View};
4
5pub trait Component {
6 /// The component's properties. The lifetime covers data borrowed from
7 /// the caller.
8 type Props<'a>: Props;
9
10 #[must_use]
11 fn props_builder<'a>() -> <Self::Props<'a> as Props>::Builder {
12 Self::Props::builder()
13 }
14
15 /// Renders the component to a [`View`].
16 ///
17 /// The returned view may borrow `cx` and the properties.
18 fn render<'cx, 'a>(
19 self,
20 cx: &'cx Cx,
21 props: Self::Props<'a>,
22 ) -> impl Future<Output = Result<impl View + 'cx>> + Send + 'cx
23 where
24 'a: 'cx,
25 Self: 'cx,
26 Self::Props<'a>: 'cx;
27}