stateless.rs

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