pub trait Flow: Send + Sync {
type View: Any + Send + Sync + Clone + 'static;
const DOMAIN: SemanticDomain;
const NAME: &'static str;
// Required method
fn project(
&self,
world: &World,
sel: &Selection,
runtime: &Runtime,
) -> Self::View;
// Provided methods
fn select(&mut self, world: &World, runtime: &Runtime) -> Selection { ... }
fn cache_key(&self, world: &World, runtime: &Runtime) -> Option<u64> { ... }
}Expand description
The typed interface between the Data layer and Lanes.
All three stages receive the engine’s [Runtime] so a Flow can look up
services, backends, or resources its domain genuinely needs (text
renderer, font cache, surface size, editor view overrides, …) without
crossing the CLAD dependency graph in awkward ways.
§Examples
A read-only Flow that projects the World into a typed View for its domain’s
Lanes. select narrows the entities; project builds the view published into
the LaneBus. (Marked ignore because a
compiling impl needs a concrete View type and a SemanticDomain from the
data layer’s domain set.)
use khora_data::ecs::{SemanticDomain, World};
use khora_data::flow::{Flow, Selection};
use khora_core::Runtime;
#[derive(Clone)]
struct MyView {
entity_count: usize,
}
struct MyFlow;
impl Flow for MyFlow {
type View = MyView;
const DOMAIN: SemanticDomain = SemanticDomain::Render;
const NAME: &'static str = "MyFlow";
fn select(&mut self, world: &World, _runtime: &Runtime) -> Selection {
// Pick the entities this domain cares about.
Selection::new()
}
fn project(&self, world: &World, _sel: &Selection, _runtime: &Runtime) -> Self::View {
MyView { entity_count: world.iter_entities().count() }
}
}Required Associated Constants§
Sourceconst DOMAIN: SemanticDomain
const DOMAIN: SemanticDomain
Domain identifier — matches the agent’s domain.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn select(&mut self, world: &World, runtime: &Runtime) -> Selection
fn select(&mut self, world: &World, runtime: &Runtime) -> Selection
Stage 1 — read-only selection of relevant entities.
Sourcefn cache_key(&self, world: &World, runtime: &Runtime) -> Option<u64>
fn cache_key(&self, world: &World, runtime: &Runtime) -> Option<u64>
Cache key for view reuse. When Some(k) matches the key of the
previously published view, the registration trampoline republishes
the cached view without re-running select/project. None (default)
disables caching — correct for flows whose projection depends on
inputs without a change signal.
Implementations MUST fold every input the projection reads into the
key: the relevant World::domain_epochs, World::instance_id
(so a different World instance never aliases a cached key), and a
bit-level hash of any runtime state consulted. A key that misses
an input produces stale views; an over-broad key merely
re-projects more often, which is always safe.
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.