51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
use crate::{gtfs, renderer};
|
|
use serde::{Serialize, Deserialize};
|
|
use std::fs;
|
|
use yaml_serde;
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
|
pub struct Config {
|
|
#[serde(rename = "gtfs")]
|
|
pub gtfs_prefs: gtfs::structs::Preferences,
|
|
|
|
#[serde(rename = "screen")]
|
|
pub screen_prefs: renderer::structs::Prefs,
|
|
}
|
|
|
|
#[derive (Debug)]
|
|
pub struct Error {
|
|
pub message: String
|
|
}
|
|
|
|
|
|
impl From<std::io::Error> for Error {
|
|
fn from(value: std::io::Error) -> Self {
|
|
return Error {
|
|
message: value.to_string(),
|
|
};
|
|
}
|
|
}
|
|
|
|
impl From<yaml_serde::Error> for Error {
|
|
fn from(value: yaml_serde::Error) -> Self {
|
|
return Error {
|
|
message: value.to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<sdl3::Error> for Error {
|
|
fn from(value: sdl3::Error) -> Self {
|
|
return Error {
|
|
message: value.to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
pub fn load_config(config_name: String) -> Result<Config, Error> {
|
|
let config_text = fs::read_to_string(config_name)?;
|
|
let config = yaml_serde::from_str(config_text.as_ref())?;
|
|
return Ok(config);
|
|
} |