1 unstable release

0.1.0 Jul 7, 2024

#264 in Build Utils

MIT/Apache

10KB
129 lines

script-meditate

crates.io

Supercharge Cargo scripts with inline structured data/configuration.

Example

Place the following in a file and make it executable, so it can be used as a standalone script:

#!/usr/bin/env -S cargo +nightly -Zscript
---cargo
[package]
edition = "2021"

[dependencies]
script-meditate = { version = "0.1.0", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
---
/*json
{
    "test": 42
}
*/

fn main() {
    let value: Data = script_meditate::extract_json_frontmatter!();
    dbg!(&value);
    assert_eq!(value.test, 42);
}

#[derive(Debug, serde::Deserialize)]
struct Data {
    test: u8,
}

Note

The script must not be placed directly inside the user's home directory.

License

Copyright 2024 dmb-ish

Dual-licensed under MIT OR Apache-2.0.

Dependencies

~0.4–1.4MB
~32K SLoC