๐ŸŒ AIๆœ็ดข & ไปฃ็† ไธป้กต
Skip to content

rinarakaki/kfl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

KFL

mdbook

  • Nominal Typing
  • Trait-Based
  • Two-Level
  • Decode-Encode Dual
  • Literal

A KDL file format parser with great error reporting and convenient derive macros.

About KDL

To give you some background on the KDL format. Here is a small example:

foo 1 "three" key="val" {
    bar
    (role)baz 1 2
}

Here is what are annotations for all the datum as described by the specification and this guide:

foo 1 "three" key="val" {                           โ•ฎ
โ”€โ”ฌโ”€ โ”ฌ โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€ โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€                             โ”‚
 โ”‚  โ”‚    โ”‚        โ•ฐโ”€โ”€โ”€โ”€โ”€ property (can be multiple) โ”‚
 โ”‚  โ”‚    โ”‚                                          โ”‚
 โ”‚  โ•ฐโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ arguments                  โ”‚
 โ”‚                                                  โ”‚
 โ•ฐโ”€โ”€ node name                                      โ”œโ”€ node "foo", with
                                                    โ”‚  "bar" and "baz"
    bar                                             โ”‚  being children
    (role)baz 1 2                                   โ”‚
     โ”€โ”€โ”ฌโ”€                                           โ”‚
       โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€ type name for node named "baz"       โ”‚
}                                                   โ•ฏ

Usage

Most common usage of this library is using derive and [decode] or [decode_children] function:

use kfl::{Decode, DecodePartial, Encode};
use std::path::PathBuf;
#[cfg(feature = "http")]
use http::Uri;

#[derive(DecodePartial, Default)]
struct Document {
    #[kfl(children)]
    routes: Vec<Route>,
    #[kfl(children)]
    plugins: Vec<Plugin>,
}

#[derive(Decode, Encode)]
struct Route {
    #[kfl(argument)]
    path: PathBuf,
    #[kfl(children)]
    subroutes: Vec<Route>,
}

#[derive(Decode, Encode)]
struct Plugin {
    #[kfl(argument)]
    name: String,
    #[cfg(feature = "http")]
    #[kfl(property)]
    url: Uri,
}

# fn main() -> miette::Result<()> {
let document = kfl::decode_children::<Document>("example.kdl", r#"
    route /api {
        route /api/v1
    }
    plugin "http" url=https://example.org/http
"#)?;
# Ok(())
# }

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

KDL decoder/encoder and derive macros in Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published