8000 GitHub - z-jxy/rpkl: Pkl bindings for Rust
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

z-jxy/rpkl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rpkl

crates.io docs.rs build status

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].

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

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

Codegen

Codegen can be enabled by adding the codegen feature.

use rpkl::{api::Evaluator, codegen::CodegenOptions};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut evaluator = Evaluator::new()?;
    let pkl_mod = evaluator.evaluate_module("example.pkl")?;
    let code: String = pkl_mod.codegen()?;
    std::fs::write("src/example.rs", code)?;
    Ok(())
}

You can also generate code using the experimental CLI.

For more info on codegen, see the docs.

About

Pkl bindings for Rust

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
0