Skip to main content

lenso_app_plan/
execution.rs

1//! Execution Adapter class identities preserved in the Resolved App Plan.
2
3use std::fmt;
4
5use serde::{Deserialize, Serialize};
6
7/// Stable App-local identity of one single-owner Kernel execution lane.
8#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
9pub struct ExecutionLaneId(String);
10
11impl ExecutionLaneId {
12    /// Creates an App-local lane identity selected by App Composition.
13    pub fn new(value: impl Into<String>) -> Self {
14        Self(value.into())
15    }
16
17    /// Returns the conventional one-lane placement used when none is authored.
18    pub fn main() -> Self {
19        Self::new("main")
20    }
21
22    /// Returns the stable App-local identity.
23    pub fn as_str(&self) -> &str {
24        &self.0
25    }
26}
27
28impl Default for ExecutionLaneId {
29    fn default() -> Self {
30        Self::main()
31    }
32}
33
34impl fmt::Display for ExecutionLaneId {
35    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
36        formatter.write_str(self.as_str())
37    }
38}
39
40/// One Plan-declared single-owner Kernel lane.
41#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
42pub struct ExecutionLanePlan {
43    id: ExecutionLaneId,
44}
45
46impl ExecutionLanePlan {
47    /// Declares one execution lane.
48    pub fn new(id: impl Into<String>) -> Self {
49        Self {
50            id: ExecutionLaneId::new(id),
51        }
52    }
53
54    /// Returns the App-local lane identity.
55    pub const fn id(&self) -> &ExecutionLaneId {
56        &self.id
57    }
58}
59
60/// Stable, open identity of the execution mechanism selected for a Module
61/// Instance.
62///
63/// Execution Adapter packages own these IDs. The Plan preserves them as opaque
64/// authoring data so third-party Adapters do not require changes to this crate.
65#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
66pub struct ExecutionClassId(String);
67
68impl ExecutionClassId {
69    /// Creates an execution-class identity selected by App Composition.
70    pub fn new(value: impl Into<String>) -> Self {
71        Self(value.into())
72    }
73
74    /// Returns the official statically linked Rust execution class.
75    pub fn native_rust() -> Self {
76        Self::new("lenso.native-rust@1")
77    }
78
79    /// Returns the official trusted Bun child-process execution class.
80    pub fn bun_child_process() -> Self {
81        Self::new("lenso.bun-process@1")
82    }
83
84    /// Returns the stable execution-class identity.
85    pub fn as_str(&self) -> &str {
86        &self.0
87    }
88}
89
90impl fmt::Display for ExecutionClassId {
91    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
92        formatter.write_str(self.as_str())
93    }
94}