base html tamplates & routes
This commit is contained in:
25
\
Normal file
25
\
Normal file
@@ -0,0 +1,25 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub debug: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
// Чтение из YAML
|
||||
pub fn load(path: &str) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let contents = fs::read_to_string(path)?;
|
||||
let config: Config = serde_yaml::from_str(&contents)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
// Запись в YAML
|
||||
pub fn save(&self, path: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let yaml_string = serde_yaml::to_string(self)?;
|
||||
fs::write(path, yaml_string)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user