Crates.io | dyn_path |
lib.rs | dyn_path |
version | 1.0.7 |
created_at | 2025-07-01 00:04:43.180382+00 |
updated_at | 2025-07-01 16:30:16.396734+00 |
description | A JavaScript-like nested object-like structure non-fallible path access interface. Access your data without serializing it just like you do in your JavaScript projects. |
homepage | |
repository | https://github.com/FlakySL/dyn_path |
max_upload_size | |
id | 1732577 |
size | 62,811 |
A JavaScript-like nested object-like structure non-fallible path access interface.
This library permits the user to access values in nested structures trough the use
of get
methods that return Option<T>
. This may be used to access specific API data
without serializing it into multiple structures and making a mess.
Imagine you just accessed a song API, this API describes everything you may or may not want to know about a specific song or songs. With the help of computed indexes you can access the same path multiple times in a variable way.
Lets try it.
use serde_json::Value as JsonValue;
use reqwest::get;
use dyn_path::dyn_access;
let response = get("https://api.platform-ending-with-fy.com/v1/tracks/5cbpoIu3YjoOwbBDGUEp3P")
.await?
.json::<JsonValue>()
.await?;
let song_name = dyn_access!(response.album.name);
let song_main_artist = dyn_access!(response.album.artists[0].name);
assert_eq!(song_name, "Car Radio");
assert_eq!(song_main_artist, "Twenty One Pilots");
Obviously this isn't a real call to a real API, but the intention can be inferred from this example anyways.
Add the following to your Cargo.toml
under the dependencies
section
dyn_path = "1.0.0"
This crate supports no_std
, meaning you can use it in your project without
depending on specific system I/O or anything else.
The crate has a default feature enabled which is std
, with this feature
the crate doesn't really use std
but it pre-includes alloc
which
permits the use of the dyn_path
macro, which uses String
to describe
a path.
You can also disable the default features and the crate will annotate no_std
.
Then use the alloc
feature if you want to have the dyn_path
macro enabled.
This repository is dual licensed, TLDR. If your repository is open source, the library is free of use, otherwise contact licensing@flaky.es for a custom license for your use case.
For more information read the license file.