4 releases
0.4.5 | Apr 28, 2024 |
---|---|
0.4.4 | Mar 5, 2024 |
0.4.3 | Feb 1, 2024 |
0.4.2 |
|
0.4.1 | Oct 24, 2023 |
#743 in Configuration
22 downloads per month
Used in 2 crates
(via afrim)
20KB
313 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, 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())]
);
Dependencies
~4.5–7MB
~130K SLoC