mirror of
https://github.com/kristoferssolo/echoes-of-ascension.git
synced 2025-10-21 18:50:34 +00:00
48 lines
1.2 KiB
Rust
48 lines
1.2 KiB
Rust
use serde::Deserialize;
|
|
use serde_aux::field_attributes::deserialize_number_from_string;
|
|
use std::{fmt::Display, str::FromStr};
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct ApplicationSettings {
|
|
#[serde(deserialize_with = "deserialize_number_from_string")]
|
|
pub port: u16,
|
|
pub host: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum Environment {
|
|
Local,
|
|
Production,
|
|
}
|
|
|
|
impl Display for Environment {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
Environment::Local => write!(f, "local"),
|
|
Environment::Production => write!(f, "production"),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl TryFrom<String> for Environment {
|
|
type Error = String;
|
|
fn try_from(value: String) -> Result<Self, Self::Error> {
|
|
match value.to_lowercase().as_str() {
|
|
"local" => Ok(Self::Local),
|
|
"production" => Ok(Self::Production),
|
|
other => Err(format!(
|
|
"{} is not supported environment. \
|
|
Use either `local` or `production`.",
|
|
other
|
|
)),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl FromStr for Environment {
|
|
type Err = String;
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
s.to_owned().try_into()
|
|
}
|
|
}
|