Skip to main content

image_rider/
config.rs

1//! Configuration for the image-rider crate
2#![warn(missing_docs)]
3#![warn(unsafe_code)]
4
5use crate::error;
6
7#[cfg(feature = "commodore")]
8use forbidden_bands::{self, Configuration as ForbiddenBandsConfiguration};
9
10/// Configuration format
11pub struct Config {
12    /// Version of the configuration root
13    pub version: String,
14
15    /// The general settings
16    pub settings: config::Config,
17
18    /// A mapping for PETSCII systems
19    /// TODO: Remove this, individual modules should create their own
20    /// keys, in an approved namespace like good little modules.
21    #[cfg(feature = "commodore")]
22    pub forbidden_bands_config: forbidden_bands::Config,
23}
24
25/// Trait that defines a set of methods that allow loading and
26/// unloading configuration data
27pub trait Configuration {
28    /// Load the configuration data from the default configuration
29    /// string
30    fn load(settings: config::Config) -> std::result::Result<Config, error::Error>;
31}
32
33impl Configuration for Config {
34    fn load(settings: config::Config) -> std::result::Result<Config, error::Error> {
35        #[cfg(feature = "commodore")]
36        let forbidden_bands_config =
37            forbidden_bands::Config::load().expect("Error loading forbidden bands config");
38
39        let config = Config {
40            version: String::from("0.1.0"),
41            settings,
42            #[cfg(feature = "commodore")]
43            forbidden_bands_config,
44        };
45
46        Ok(config)
47    }
48}