Crates.io | foundations_ext |
lib.rs | foundations_ext |
version | 0.0.4 |
source | src |
created_at | 2024-10-29 23:55:56.793528 |
updated_at | 2024-11-07 22:40:46.435686 |
description | Foundation extensions published from the ewe_platform but usable by all |
homepage | |
repository | https://github.com/ewe-studios/ewe_platform |
max_upload_size | |
id | 1427762 |
size | 36,530 |
An extension crate that provides varying trait extensions for different libraries and utilities. The goal is to have a central place for where such extensions can live without being specifically tied down to the ewe_platform namespace.
Provides useful extensions for the serde crate, it takes inspiration from the value-ext crate by Jeremy Chone.
If you've read Data Oriented Programming or have used kotlin and love the ease of interacting with basic data structures like maps and list then this will be super familiar.
I have taking inspiration and code from value-ext crate and expanded support for toml based Value
types as well to make it super-easy to work with such raw types.
use serde_json::json;
use foundations_ext::serde_ext::DynamicValueExt;
use foundations_ext::serde_ext::JsonValueExt;
let mut value = json!({"tokens": 3, "hello": {"word": "hello"}});
// get a copy of the value
let actual_value: String = value.d_get("/happy/word")?;
// take the value in the path thereby removing from map
let content: String = value.d_take("/hello/word")?;
// add a value into map
value.d_insert("/happy/word", "hello")?;
value.d_walk(|tree, key| {
// do something
true
});
use toml::toml;
use foundations_ext::serde_ext::DynamicValueExt;
use foundations_ext::serde_ext::TomlValueExt;
let mut value = toml::Value::Table(toml! {
token=3
[hello]
word = "hello"
[hello.wreckage]
where = "londo"
});
// get a copy of the value
let actual_value: String = value.d_get("/happy/word")?;
// take the value in the path thereby removing from map
let content: String = value.d_take("/hello/word")?;
// add a value into map
value.d_insert("/happy/word", "hello")?;
value.d_walk(|tree, key| {
// do something
true
});