#ewe-platform #ewestudios-platform #extension #foundation #traits

foundations_ext

Foundation extensions published from the ewe_platform but usable by all

4 releases

new 0.0.4 Nov 7, 2024
0.0.3 Nov 7, 2024
0.0.2 Nov 7, 2024
0.0.1 Oct 29, 2024

#1 in #ewe-platform

Download history 140/week @ 2024-10-28

140 downloads per month
Used in 2 crates

Apache-2.0

37KB
821 lines

FoundationsExt

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.

Crates

serde_ext

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.

  • JSON
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
});

  • TOML
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
});

Inspirations

Dependencies

~5–11MB
~128K SLoC