lumen_core/traits.rs
1//! Marker traits identifying backend roles, plus the [`Bindable`] trait declaring a component as a property-bus participant.
2//!
3//! Concrete backends register systems via a [`crate::app::Plugin`] into the appropriate [`crate::tick::TickStage`]; the marker
4//! traits provide a type-level identifier only.
5
6use crate::property_store::PropertyValue;
7use bevy_ecs::component::Component;
8
9/// Marker trait implemented by render backends. The accompanying plugin installs the backend as a (possibly `NonSend`) render-world resource and registers systems into [`crate::render_world::RenderStage`].
10pub trait Renderer: 'static {}
11
12/// Marker trait implemented by layout engines. Plugins register systems into [`crate::tick::TickStage::LayoutSync`].
13pub trait LayoutEngine: Send + Sync {}
14
15/// Marker trait implemented by window backends. Plugins register systems into [`crate::tick::TickStage::Input`].
16pub trait WindowBackend: Send + Sync {}
17
18/// Marker trait implemented by accessibility bridges. Plugins register systems into [`crate::tick::TickStage::A11ySync`].
19pub trait A11yBackend: Send + Sync {}
20
21/// Marker trait implemented by async-task runtimes.
22pub trait Spawn: Send + Sync {}
23
24/// Marker trait implemented by one-shot timer runtimes.
25pub trait Timer: Send + Sync {}
26
27/// Declares that a [`Component`] participates in the entity-property bus exposed by [`crate::property_store::PropertyStore`].
28///
29/// The intent is to collapse the `BindText` / `BindChecked` / `BindValue` zoo onto a single, type-erased property
30/// pipeline. The trait defines the shape; there is no registration call on [`crate::app::App`] yet, so implementing
31/// it does not wire anything up, and no component in the workspace implements it yet. The shape it is designed
32/// for is [`crate::components::TextContent`] (`NAME = "text"`, `Value = Arc<str>`).
33pub trait Bindable: Component {
34 /// Bus name for this component. Markup `bind-<NAME>="signal"` wires `PropertyKey::Entity(e, NAME)` to `PropertyKey::Global("signal")`.
35 const NAME: &'static str;
36
37 /// Typed value carried over the bus. Must round-trip through [`PropertyValue`].
38 type Value: Into<PropertyValue> + From<PropertyValue>;
39
40 /// Reads the component into its bus value.
41 fn read(&self) -> Self::Value;
42
43 /// Writes a bus value into the component.
44 fn write(&mut self, v: Self::Value);
45}