1use std::marker::PhantomData;
2
3use crate::Element;
4
5pub struct Stateless<E: Element<State = ()>, S> {
6 element: E,
7 parent_state_type: PhantomData<S>,
8}
9
10impl<E: Element<State = ()>, S: 'static> Element for Stateless<E, S> {
11 type State = S;
12 type FrameState = E::FrameState;
13
14 fn layout(
15 &mut self,
16 _: &mut Self::State,
17 cx: &mut crate::ViewContext<Self::State>,
18 ) -> anyhow::Result<(crate::LayoutId, Self::FrameState)> {
19 cx.erase_state(|cx| self.element.layout(&mut (), cx))
20 }
21
22 fn paint(
23 &mut self,
24 layout: crate::Layout,
25 _: &mut Self::State,
26 frame_state: &mut Self::FrameState,
27 cx: &mut crate::ViewContext<Self::State>,
28 ) -> anyhow::Result<()> {
29 cx.erase_state(|cx| self.element.paint(layout, &mut (), frame_state, cx))
30 }
31}