#pkl #configuration-language #apple #codegen

rpkl

Bindings and codegen for Apple's Pkl configuration language

8 releases

0.3.5 Nov 13, 2024
0.3.4 Oct 5, 2024
0.3.3 Sep 20, 2024
0.3.1 Aug 5, 2024
0.1.0 Jun 28, 2024

#195 in Configuration

Download history 16/week @ 2024-08-19 33/week @ 2024-08-26 92/week @ 2024-09-02 132/week @ 2024-09-09 216/week @ 2024-09-16 22/week @ 2024-09-23 466/week @ 2024-09-30 511/week @ 2024-10-07 226/week @ 2024-10-14 163/week @ 2024-10-21 139/week @ 2024-10-28 96/week @ 2024-11-04 345/week @ 2024-11-11 223/week @ 2024-11-18 444/week @ 2024-11-25 205/week @ 2024-12-02

1,238 downloads per month
Used in 2 crates

MIT license

93KB
2.5K SLoC

rpkl

crates.io docs.rs

Language bindings to Pkl for Rust.

Requires the pkl binary to be available on your path. You can install pkl for your os using the steps from their docs: https://pkl-lang.org/main/current/pkl-cli/index.html#installation

Usage

ip = "127.0.0.1"

database {
    username = "admin"
    password = "secret"
}
#[derive(Deserialize)]
struct Config {
    ip: String,
    database: Database,
}

#[derive(Deserialize)]
struct Database {
    username: String,
    password: String,
}

let config: Config = rpkl::from_config("./config.pkl")?;

Evaluator Options

You can pass options to the evaluator, such as properties, by using from_config_with_options.

let options = EvaluatorOptions::default()
.properties([("username", "root"), ("password", "password123")]);

let config: Config = rpkl::from_config_with_options("./config.pkl", Some(options))?;

Codegen

Mostly works, but still a WIP. If you want to try it out, you can enable the codegen feature.

let mut evaluator = rpkl::evaluator::Evaluator::new()?;
let pkl_mod = evaluator.evaluate_module(PathBuf::from("./config.pkl"))?;
pkl_mod.codegen()?;

Dependencies

~0.8–7MB
~53K SLoC