Skip to main content

Flow

Trait Flow 

Source
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§

Source

const DOMAIN: SemanticDomain

Domain identifier — matches the agent’s domain.

Source

const NAME: &'static str

Stable identifier — used for telemetry and ordering.

Required Associated Types§

Source

type View: Any + Send + Sync + Clone + 'static

The typed view this Flow publishes into the LaneBus. Clone so the registration trampoline can republish a cached view without re-running select/project (views hold Arcs and plain data, so cloning is cheap relative to a full re-projection).

Required Methods§

Source

fn project( &self, world: &World, sel: &Selection, runtime: &Runtime, ) -> Self::View

Stage 2 — read-only projection of the world into a View.

Provided Methods§

Source

fn select(&mut self, world: &World, runtime: &Runtime) -> Selection

Stage 1 — read-only selection of relevant entities.

Source

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.

Implementors§

Source§

impl Flow for AudioFlow

Source§

const DOMAIN: SemanticDomain = SemanticDomain::Audio

Source§

const NAME: &'static str = "audio"

Source§

type View = AudioView

Source§

impl Flow for PhysicsFlow

Source§

const DOMAIN: SemanticDomain = SemanticDomain::Physics

Source§

const NAME: &'static str = "physics"

Source§

type View = PhysicsView

Source§

impl Flow for RenderFlow

Source§

const DOMAIN: SemanticDomain = SemanticDomain::Render

Source§

const NAME: &'static str = "render"

Source§

type View = RenderWorld

Source§

impl Flow for ShadowFlow

Source§

const DOMAIN: SemanticDomain = SemanticDomain::Render

Source§

const NAME: &'static str = "shadow"

Source§

type View = ShadowView

Source§

impl Flow for UiFlow

Source§

const DOMAIN: SemanticDomain = SemanticDomain::Ui

Source§

const NAME: &'static str = "ui"

Source§

type View = UiScene