use crate::{Error, Result};
use std::str::FromStr;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Role {
#[default]
All,
Api,
Worker,
}
impl Role {
pub const fn includes_api(self) -> bool {
matches!(self, Self::All | Self::Api)
}
pub const fn includes_workers(self) -> bool {
matches!(self, Self::All | Self::Worker)
}
}
impl FromStr for Role {
type Err = Error;
fn from_str(value: &str) -> Result<Self> {
match value {
"all" => Ok(Self::All),
"api" => Ok(Self::Api),
"worker" => Ok(Self::Worker),
_ => Err(Error::Registration(
"role must be all, api, or worker".into(),
)),
}
}
}