1use AssemblyErrorImpl::*;
4
5pub use crate::ids::GlobalReactionId;
6pub use crate::scheduler::assembly_impl::*;
8pub use crate::triggers::{TriggerId, TriggerLike};
9use crate::{DebugInfoRegistry, LocalReactionId, ReactorBehavior};
10pub(crate) type PortId = TriggerId;
11
12pub trait ReactorInitializer: ReactorBehavior {
20 type Wrapped;
23 type Params;
25 const MAX_REACTION_ID: LocalReactionId;
27
28 fn assemble(args: Self::Params, assembler: AssemblyCtx<Self>) -> AssemblyResult<FinishedReactor<Self>>
32 where
33 Self: Sized;
34}
35
36pub type AssemblyResult<T = ()> = Result<T, AssemblyError>;
37
38pub struct AssemblyError(pub(crate) AssemblyErrorImpl);
42
43impl AssemblyError {
44 pub(crate) fn lift(self, debug: &DebugInfoRegistry) -> String {
45 self.display(debug)
46 }
47}
48
49pub(crate) enum AssemblyErrorImpl {
50 CyclicDependency(PortId, PortId),
51 CyclicDependencyGraph,
52 CannotBind(PortId, PortId),
53 IdOverflow,
54}
55
56impl AssemblyError {
57 fn display(&self, debug: &DebugInfoRegistry) -> String {
58 match self.0 {
59 CyclicDependency(upstream, downstream) => format!(
60 "Port {} is already in the downstream of port {}",
61 debug.fmt_component(upstream),
62 debug.fmt_component(downstream)
63 ),
64 CyclicDependencyGraph => "Cyclic dependency graph".to_string(),
65 CannotBind(upstream, downstream) => format!(
66 "Cannot bind {} to {}, downstream is already bound",
67 debug.fmt_component(upstream),
68 debug.fmt_component(downstream)
69 ),
70 IdOverflow => "Overflow when allocating component ID".to_string(),
71 }
72 }
73}
74
75#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
77pub enum PortKind {
78 Input,
79 Output,
80 ChildInputReference,
81 ChildOutputReference,
82}