hyperion_framework/containerisation/container_state.rs
1// -------------------------------------------------------------------------------------------------
2// Hyperion Framework
3// https://github.com/robert-hannah/hyperion-framework
4//
5// A lightweight component-based TCP framework for building service-oriented Rust applications with
6// CLI control, async messaging, and lifecycle management.
7//
8// Copyright 2025 Robert Hannah
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14// http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21// -------------------------------------------------------------------------------------------------
22
23// Package
24use serde::{Deserialize, Serialize};
25
26#[repr(usize)]
27#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
28pub enum ContainerState {
29 Running = 0, // Container is running
30 MissingConnections = 1, // Container has missing connections which can be restarted
31 DeadComponent = 2, // Component is dead but can be restarted
32 ShuttingDown = 3, // Container is closing
33 Closed = 4, // Container is closed and cannot be restarted
34}
35
36impl From<usize> for ContainerState {
37 fn from(value: usize) -> Self {
38 match value {
39 0 => ContainerState::Running,
40 1 => ContainerState::MissingConnections,
41 2 => ContainerState::DeadComponent,
42 3 => ContainerState::ShuttingDown,
43 4 => ContainerState::Closed,
44 _ => panic!("Invalid component state value"),
45 }
46 }
47}