pklr
A pure Rust parser and evaluator for Apple's Pkl configuration language. No external binary or CLI required.
Features
- Lexer, parser, and evaluator written entirely in Rust
- Evaluates
.pklfiles toserde_json::Value - Import and amends resolution for local files
- Persistent caching, cache preloading, and offline evaluation for
package://imports - String interpolation, lambdas, higher-order methods
- Rich error diagnostics via miette
Usage
use eval_to_json;
let json = eval_to_json?;
println!;
The default synchronous API uses blocking HTTP and creates no thread or Tokio runtime. A default build has no Tokio dependency.
Asynchronous applications can disable default features and enable async plus
any optional features they need:
= { = "2", = false, = ["async", "package-zip", "miette-diagnostics"] }
let json = eval_to_json_async.await?;
Async evaluation and analyze_imports_async use Tokio filesystem operations;
blocking-only work such as ZIP extraction and glob walking runs on Tokio's
blocking pool. For direct construction, use Evaluator::new_async(); the
unsuffixed Evaluator::new() always selects blocking capabilities.
Use EvaluatorBuilder::http_agent with a custom pklr::ureq::Agent for
synchronous HTTP configuration. The async AsyncEvaluatorBuilder::http_client
accepts a custom pklr::reqwest::Client.
Package downloads can be shared across evaluator instances and reused without network access:
A host that already ships a copy of a package can seed the cache with it, so a config importing that package evaluates without any network round trip:
static PACKAGE: & = include_bytes!;
Cached content already on disk wins, so preloading never overrides a package fetched from the network, and a config pinning a different version still resolves that version normally.
License
MIT