frame_core/component.rs
1//! Component identity and declarations.
2
3use std::time::Duration;
4
5use frame_capability::CapabilityRequest;
6use serde::{Deserialize, Serialize};
7
8pub use frame_capability::{ComponentId, ComponentIdParseError};
9
10/// Metadata declaring a native component's identity, process tree, and contracts.
11#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
12pub struct ComponentMeta {
13 /// Stable identity, independent of version and bytecode.
14 pub id: ComponentId,
15 /// Human-readable component name.
16 pub name: String,
17 /// Version that may change without changing [`Self::id`].
18 pub version: String,
19 /// Registered components that must be running before this component starts.
20 pub requires: Vec<ComponentId>,
21 /// Service-wiring contracts contributed to the system.
22 ///
23 /// This is lexically distinct from host authority in
24 /// [`crate::capability`].
25 pub provides: Vec<ServiceCapability>,
26 /// Host-mediated authority requested by the manifest, never granted by declaration.
27 pub needs: Vec<CapabilityRequest>,
28 /// Retained specifications for linked child processes, in stop order.
29 pub children: Vec<ChildSpec>,
30 /// Explicit one-for-one policy; absence is rejected during registration.
31 pub supervision: Option<SupervisionPolicy>,
32}
33
34/// A named service-wiring contract that a component contributes.
35///
36/// Host authority is represented separately by [`crate::capability::Capability`].
37#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
38pub struct ServiceCapability {
39 /// Globally unique capability identifier.
40 pub id: String,
41 /// Human-readable description.
42 pub description: String,
43}
44
45/// A retained specification for one persistent linked child.
46#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
47pub struct ChildSpec {
48 /// Name used for status, commands, and failure reports.
49 pub name: String,
50 /// Loaded BEAM module containing the entrypoint.
51 pub module: String,
52 /// Exported entry function.
53 pub function: String,
54 /// Entrypoint arguments materialized when the child is spawned.
55 pub arguments: Vec<ChildArgument>,
56 /// Integer mailbox message used for a liveness round-trip.
57 pub liveness_message: i64,
58 /// Integer mailbox message requesting an orderly normal exit.
59 pub stop_message: i64,
60}
61
62/// A serializable child-entrypoint argument supported by the native host seam.
63#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
64pub enum ChildArgument {
65 /// PID of the component's host-native supervisor.
66 SupervisorPid,
67 /// A BEAM small integer.
68 Integer(i64),
69 /// An atom interned in the scheduler's atom table.
70 Atom(String),
71}
72
73/// Required one-for-one restart intensity declaration.
74#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
75pub struct SupervisionPolicy {
76 /// Maximum replacements admitted during one rolling window.
77 pub max_restarts: usize,
78 /// Rolling window used to count replacements.
79 pub window: Duration,
80}