Skip to main content

telex/
component.rs

1use crate::scope::Scope;
2use crate::View;
3
4/// A component that can render itself to a View.
5pub trait Component {
6    /// Render this component to a View tree.
7    fn render(&self, cx: Scope) -> View;
8}
9
10/// Blanket implementation for closures that take Scope and return View.
11/// This enables: rte::run(|cx| view! { ... })
12impl<F> Component for F
13where
14    F: Fn(Scope) -> View,
15{
16    fn render(&self, cx: Scope) -> View {
17        self(cx)
18    }
19}