starlane_core/
actor.rs

1use std::fmt;
2
3use std::str::FromStr;
4
5use serde::{Deserialize, Serialize};
6
7use crate::error::Error;
8
9use crate::names::Name;
10
11pub type ActorSpecific = Name;
12pub type GatheringSpecific = Name;
13
14#[derive(Debug, Eq, PartialEq, Hash, Clone, Serialize, Deserialize)]
15pub enum ActorKind {
16    Stateful,
17    Stateless,
18}
19
20impl ActorKind {
21    // it looks a little pointless but helps get around a compiler problem with static_lazy values
22    pub fn as_kind(&self) -> Self {
23        self.clone()
24    }
25}
26
27impl fmt::Display for ActorKind {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        write!(
30            f,
31            "{}",
32            match self {
33                ActorKind::Stateful => "Stateful".to_string(),
34                ActorKind::Stateless => "Stateless".to_string(),
35            }
36        )
37    }
38}
39
40impl FromStr for ActorKind {
41    type Err = Error;
42
43    fn from_str(s: &str) -> Result<Self, Self::Err> {
44        match s {
45            "Stateful" => Ok(ActorKind::Stateful),
46            "Stateless" => Ok(ActorKind::Stateless),
47            _ => Err(format!("could not find ActorKind: {}", s).into()),
48        }
49    }
50}