pub const DESCRIPTOR_VERSION: &str = "fiber-descriptor-v1";
pub const PROFILE: &str = "legacy_rust";
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FiberState {
Pending,
Loading,
Active,
Paused,
Suspended,
Unloading,
Disposed,
Failed(String),
}
impl FiberState {
pub const fn name(&self) -> &'static str {
match self {
Self::Pending => "pending",
Self::Loading => "loading",
Self::Active => "active",
Self::Paused => "paused",
Self::Suspended => "suspended",
Self::Unloading => "unloading",
Self::Disposed => "disposed",
Self::Failed(_) => "error",
}
}
pub const fn published_name(&self) -> &'static str {
match self {
Self::Pending => "pending",
Self::Loading => "loading",
Self::Active => "active",
Self::Paused => "paused",
Self::Suspended => "suspended",
Self::Unloading => "unloading",
Self::Disposed => "disposed",
Self::Failed(_) => "failed",
}
}
}
pub fn initial_state(coeffects_empty: bool) -> FiberState {
if coeffects_empty { FiberState::Active } else { FiberState::Pending }
}
#[inline]
pub const fn valid_transition(from: &FiberState, to: &FiberState) -> bool {
matches!(
(from, to),
(FiberState::Pending, FiberState::Loading) |
(FiberState::Pending, FiberState::Active) |
(FiberState::Loading, FiberState::Active) |
(FiberState::Loading, FiberState::Failed(_)) |
(FiberState::Active, FiberState::Active) |
(FiberState::Active, FiberState::Loading) |
(FiberState::Active, FiberState::Paused) |
(FiberState::Active, FiberState::Suspended) |
(FiberState::Active, FiberState::Unloading) |
(FiberState::Active, FiberState::Failed(_)) |
(FiberState::Paused, FiberState::Active) |
(FiberState::Suspended, FiberState::Active) |
(FiberState::Suspended, FiberState::Unloading) |
(FiberState::Unloading, FiberState::Disposed) |
(FiberState::Unloading, FiberState::Failed(_))
)
}
pub const fn state_role(state: &FiberState) -> &'static str {
match state {
FiberState::Pending => "InitialBottom",
FiberState::Loading => "Intermediate",
FiberState::Active => "Intermediate",
FiberState::Paused => "Intermediate",
FiberState::Suspended => "Intermediate",
FiberState::Unloading => "Intermediate",
FiberState::Disposed => "TerminalTop",
FiberState::Failed(_) => "Exception",
}
}
pub const fn trace_name(state: &FiberState) -> Option<&'static str> {
match state {
FiberState::Pending => Some("PENDING"),
FiberState::Loading => Some("LOADING"),
FiberState::Active => Some("ACTIVE"),
FiberState::Suspended => Some("SUSPENDED"),
FiberState::Unloading => Some("UNLOADING"),
FiberState::Disposed => Some("DISPOSED"),
_ => None,
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FiberBypass {
pub name: &'static str,
pub method: &'static str,
pub sources: &'static [&'static str],
pub targets: &'static [&'static str],
pub drains: bool,
}
pub const FIBER_STATES: &[&str] = &[
"pending",
"loading",
"active",
"paused",
"suspended",
"unloading",
"disposed",
"error",
];
pub const INITIAL_STATE: &str = "pending";
pub const TERMINAL_STATES: &[&str] = &["disposed"];
pub const VALID_TRANSITIONS: &[(&str, &[&str])] = &[
("pending", &["loading", "active"]),
("loading", &["active", "error"]),
("active", &["loading", "active", "paused", "suspended", "unloading", "error"]),
("paused", &["active"]),
("suspended", &["active", "unloading"]),
("unloading", &["disposed", "error"]),
("disposed", &[]),
("error", &[]),
];
pub const DRAINING_TRANSITIONS: &[(&str, &str)] = &[];
pub const TERMINAL_PATHS: &[(&str, &[&str])] = &[
("pending", &["active", "unloading", "disposed"]),
("loading", &["active", "unloading", "disposed"]),
("active", &["unloading", "disposed"]),
("paused", &["active", "unloading", "disposed"]),
("suspended", &["unloading", "disposed"]),
("unloading", &["disposed"]),
("disposed", &[]),
];
pub const STATE_ROLES: &[(&str, &str)] = &[
("pending", "InitialBottom"),
("loading", "Intermediate"),
("active", "Intermediate"),
("paused", "Intermediate"),
("suspended", "Intermediate"),
("unloading", "Intermediate"),
("disposed", "TerminalTop"),
("error", "Exception"),
];
pub const CORE_STATES: &[&str] = &["pending", "loading", "active", "unloading", "disposed"];
pub const TRACE_NAMES: &[(&str, &str)] = &[
("pending", "PENDING"),
("loading", "LOADING"),
("active", "ACTIVE"),
("suspended", "SUSPENDED"),
("unloading", "UNLOADING"),
("disposed", "DISPOSED"),
];
pub const DESCRIPTOR_STATES: &[&str] = &[
"pending",
"loading",
"active",
"paused",
"suspended",
"unloading",
"disposed",
"error",
];
pub const PROFILE_STATES: &[(&str, &[&str])] = &[
("canonical", &["pending", "loading", "active", "suspended", "unloading", "disposed", "error"]),
("legacy_python", &["pending", "loading", "active", "unloading", "disposed"]),
("legacy_rust", &["pending", "loading", "active", "paused", "suspended", "unloading", "disposed", "error"]),
];
pub const PROFILE_TRANSITIONS: &[(&str, &[(&str, &[&str])])] = &[
("canonical", &[
("pending", &["loading", "error"]),
("loading", &["active", "error"]),
("active", &["suspended", "unloading", "error"]),
("suspended", &["active", "unloading", "error"]),
("unloading", &["disposed", "error"]),
("disposed", &[]),
("error", &["disposed"]),
]),
("legacy_python", &[
("pending", &["loading"]),
("loading", &["active", "disposed"]),
("active", &["unloading"]),
("unloading", &["disposed"]),
("disposed", &[]),
]),
("legacy_rust", &[
("pending", &["loading", "active"]),
("loading", &["active", "error"]),
("active", &["loading", "active", "paused", "suspended", "unloading", "error"]),
("paused", &["active"]),
("suspended", &["active", "unloading"]),
("unloading", &["disposed", "error"]),
("disposed", &[]),
("error", &[]),
]),
];
pub const PUBLISHED_TRANSITIONS: &[(&str, &[&str])] = &[
("pending", &["loading", "active"]),
("loading", &["active", "failed"]),
("active", &["loading", "active", "paused", "suspended", "unloading", "failed"]),
("paused", &["active"]),
("suspended", &["active", "unloading"]),
("unloading", &["disposed", "failed"]),
("disposed", &[]),
("failed", &[]),
];
pub const CORE_TRACE: [&str; 5] = ["PENDING", "LOADING", "ACTIVE", "UNLOADING", "DISPOSED"];
pub mod trace {
pub const PENDING: &str = "PENDING";
pub const LOADING: &str = "LOADING";
pub const ACTIVE: &str = "ACTIVE";
pub const SUSPENDED: &str = "SUSPENDED";
pub const UNLOADING: &str = "UNLOADING";
pub const DISPOSED: &str = "DISPOSED";
}
pub const RUST_DISPOSE: FiberBypass = FiberBypass { name: "rust_dispose", method: "dispose", sources: &["pending", "loading", "active", "paused", "suspended", "unloading", "error"], targets: &["unloading"], drains: true };
pub const BYPASSES: &[FiberBypass] = &[
RUST_DISPOSE,
];