Crates.io | plugx-input |
lib.rs | plugx-input |
version | 0.3.1 |
source | src |
created_at | 2023-09-23 20:00:15.705102 |
updated_at | 2023-12-28 08:15:14.056348 |
description | simple and flexible data-structure with diff, merge, and validation. |
homepage | https://crates.io/crates/plugx-input |
repository | https://github.com/plugx-rs/plugx-input |
max_upload_size | |
id | 981472 |
size | 149,894 |
A simple and flexible data-structure for configuration and state manipulation of plugins.
Package | Documentation | Repository
use plugx_input::Input;
let mut map = Input::new_map();
map.map_mut().insert("key".into(), Input::from([1, 2, 3]));
let inner_list = map
.map_mut() // &mut Hashmap<String, Input>
.get_mut("key") // Option<&mut Input>
.unwrap() // &mut Input (which is a list)
.list_mut(); // &mut Vec<Input>
*inner_list.get_mut(0).unwrap() = 3.14.into();
*inner_list.get_mut(1).unwrap() = true.into();
*inner_list.get_mut(2).unwrap() = "hello world".into();
println!("{map}");
// prints:
// {"key": [3.14, true, "hello world"]}
use plugx_input::Input;
use plugx_input::diff::{diff, InputDiff};
let mut map = Input::new_map(); // {}
map.map_mut().insert("foo".into(), Input::new_map()); // {"foo": {}}
map // {"foo": {"bar": [50, 60, 70]}}
.map_mut()
.get_mut("foo").unwrap()
.map_mut()
.insert("bar".into(), Input::from([50, 60, 70]));
let mut map2 = map.clone(); // {"foo": {"bar": [50, 60, 70]}}
*map2 // {"foo": {"bar": [100, 60, 70]}}
.map_mut()
.get_mut("foo").unwrap()
.map_mut()
.get_mut("bar").unwrap()
.list_mut()
.get_mut(0).unwrap()
.int_mut() = 100;
diff(
&map,
&map2,
&mut |diff: InputDiff| {
println!("value {} {}", diff.position(), diff.action())
}
);
// prints:
// value [foo][bar][0] increased by 50
use plugx_input::Input;
use plugx_input::merge::merge;
let mut map = Input::new_map(); // {}
map.map_mut().insert("foo".into(), Input::new_map()); // {"foo": {}}
map // {"foo": {"bar": false}}
.map_mut()
.get_mut("foo").unwrap()
.map_mut()
.insert("bar".into(), false.into());
let mut map2 = Input::new_map(); // {}
map2.map_mut().insert("foo".into(), Input::new_map()); // {"foo": {}}
map2 // {"foo": {"baz": true}}
.map_mut()
.get_mut("foo").unwrap()
.map_mut()
.insert("baz".into(), true.into());
merge(&mut map, &map2);
println!("{map}");
// prints:
// {"foo": {"bar": false, "baz": true}}
Input
.I ❤️ PR from everyone, and I appreciate your help but before opening a PR, file an issue and describe your feature, fix, etc.