Skip to main content

StatelessWidget

Trait StatelessWidget 

Source
pub trait StatelessWidget: 'static {
    // Required method
    fn build(&self, cx: &BuildContext<'_>) -> Box<dyn Widget>;

    // Provided method
    fn into_widget(self) -> Component
       where Self: Sized { ... }
}
Expand description

A widget with nothing to remember: it says what it looks like from what it is configured with, and from nothing else.

Any Fn(&BuildContext) -> Box<dyn Widget> is one, which is how a function becomes a component — and, with hooks, one that remembers.

Required Methods§

Source

fn build(&self, cx: &BuildContext<'_>) -> Box<dyn Widget>

The widget this one stands for. Called whenever the tree is rebuilt.

Provided Methods§

Source

fn into_widget(self) -> Component
where Self: Sized,

This component as a widget: what goes in a column![..], a Scaffold’s body, a route’s page.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F> StatelessWidget for F
where F: Fn(&BuildContext<'_>) -> Box<dyn Widget> + 'static,