3 releases

0.4.4 Mar 5, 2024
0.4.3 Feb 1, 2024
0.4.2 Jan 31, 2024
0.4.1 Oct 24, 2023

#472 in Configuration

Download history 18/week @ 2024-01-29 48/week @ 2024-02-19 14/week @ 2024-02-26 151/week @ 2024-03-04 52/week @ 2024-03-11 1/week @ 2024-03-25 22/week @ 2024-04-01

82 downloads per month
Used in 2 crates (via afrim)

MIT license

21KB
310 lines

Afrim Config Manager

Manage the configuration of the afrim input method.

Features

  • rhai: Enable the usage of rhai scripts.
  • rhai-wasm: Like rhai but wasm compatible.

lib.rs:

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, Box<dyn error::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())]
);

Dependencies

~4.5–7MB
~127K SLoC