Skip to main content

atomr_patterns/
topology.rs

1//! [`Topology`] — common materialization surface for every pattern.
2//!
3//! Each `*Pattern::build()` produces a value implementing this trait.
4//! Calling [`Topology::materialize`] spawns the pattern's actors under a
5//! single named root in the user-guardian (`/user/<name>`) so the
6//! dashboard's topology view renders the pattern as a cohesive subtree.
7
8use async_trait::async_trait;
9
10use atomr_core::actor::ActorSystem;
11
12use crate::PatternError;
13
14/// Inspectable, materializable description of a pattern's actor + stream
15/// topology. Implementors hand back strongly-typed `Handles` after
16/// materialization — you get a [`crate::Repository`], a
17/// [`crate::cqrs::ProjectionHandle`], etc., depending on the pattern.
18#[async_trait]
19pub trait Topology: Send + 'static {
20    /// The handle bundle returned after materialization.
21    type Handles: Send + 'static;
22
23    /// Spawn the pattern's actors and start its streams. Idempotent
24    /// w.r.t. the returned handles, but each call to `materialize`
25    /// spawns a fresh subtree — invoke it once per pattern instance.
26    async fn materialize(self, system: &ActorSystem) -> Result<Self::Handles, PatternError<()>>;
27}