pub trait Component {
type State: 'static + Any + Send + Sync;
type Message: 'static;
type Output: 'static;
// Required methods
fn mount(&self) -> Self::State;
fn view<'a>(&'a self, state: &'a Self::State) -> Node<'a, Self::Message>;
// Provided methods
fn update(
&self,
_message: Self::Message,
_state: State<'_, Self::State>,
_context: Context<'_, Self::Message, Self::Output>,
) { ... }
fn style() -> StyleBuilder { ... }
fn into_node<'a>(self) -> Node<'a, Self::Output>
where Self: 'a + Sized { ... }
fn class<'a>(self, class: &'a str) -> Node<'a, Self::Output>
where Self: 'a + Sized { ... }
fn key<'a, K>(self, key: K) -> Node<'a, Self::Output>
where Self: 'a + Sized,
K: Hash { ... }
}
Expand description
A re-usable component for defining a fragment of a user interface. Components are the main building block for user interfaces in pixel-widgets.
The examples in this repository all implement some kind of Component
,
check them out if you just want to read some code.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn update(
&self,
_message: Self::Message,
_state: State<'_, Self::State>,
_context: Context<'_, Self::Message, Self::Output>,
)
fn update( &self, _message: Self::Message, _state: State<'_, Self::State>, _context: Context<'_, Self::Message, Self::Output>, )
Update the Component
state in response to the message
.
Asynchronous operations can be submitted to the context
,
which will result in more update
calls in the future.
Messages for the parent Component
or root can also be submitted through the context
.
Sourcefn style() -> StyleBuilder
fn style() -> StyleBuilder
Returns a StyleBuilder
with styling information scoped to this component.
This method will be called when you call
StyleBuilder::component()
when building your style.
Sourcefn into_node<'a>(self) -> Node<'a, Self::Output>where
Self: 'a + Sized,
fn into_node<'a>(self) -> Node<'a, Self::Output>where
Self: 'a + Sized,
Converts the component into a Node
. This is used by the library to
instantiate the component in a user interface.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.