Crate afrim_config

source ·
Expand description

Library to manage the configuration of the afrim input method.

It’s based on the top of the toml crate.

§Example

use afrim_config::Config;
use std::path::Path;

let filepath = Path::new("./data/config_sample.toml");
let conf = Config::from_file(&filepath).unwrap();

In case that you want control the filesystem (reading of file), you can use the Config::from_filesystem method.

§Example

use afrim_config::{Config, FileSystem};
use std::{error, path::Path, string::String};

// Implements a custom filesystem.
struct File {
    source: String,
}

impl File {
    pub fn new(source: String) -> Self {
        Self { source }
    }
}

impl FileSystem for File {
    fn read_to_string(&self, filepath: &Path) -> Result<String, std::io::Error> {
        Ok(self.source.to_string())
    }
}

// Sets the config file.
let config_file = File::new(r#"
[core]
auto_commit = false

[data]
"n*" = "ŋ"
"#.to_owned());

// Loads the config file.
let config = Config::from_filesystem(&Path::new("."), &config_file).unwrap();

assert_eq!(config.core.clone().unwrap().auto_commit, Some(false));
// Note that the auto_capitalize is enabled by default.
assert_eq!(
    Vec::from_iter(config.extract_data().into_iter()),
    vec![("n*".to_owned(), "ŋ".to_owned()), ("N*".to_owned(), "Ŋ".to_owned())]
);

Structs§

  • Holds information about a configuration.
  • Core information about a configuration.

Traits§