Serde_cursor: Extract nested field of JSON without making intermediate structs

Hi!

serde_cursor allows you to specify how to get the desired parts of any serde-compatible data format, such as JSON - using very lightweight syntax, and without loading the entire document into memory!

Extract version from Cargo.toml:

use serde_cursor::Cursor;

let data = r#"
    [workspace.package]
    version = "0.1"
"#;

let version: String = toml::from_str::<Cursor!(workspace.package.version)>(&data)?.0;

assert_eq!(version, "0.1");

Cursor!(workspace.package.version) is the magic juice - this macro expands to a type implementing Deserialize.

5 Likes