Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serde Support #71

Open
scott-wilson opened this issue Apr 5, 2024 · 7 comments
Open

Serde Support #71

scott-wilson opened this issue Apr 5, 2024 · 7 comments

Comments

@scott-wilson
Copy link

This is another crack at Serde support (linking #17 for historical reference).

The basic API that I'm thinking of would look something like this (borrowing from Serde JSON):

#[derive(Serialize, Deserialize)]
struct Config {
    root_dir: PathBuf,
    iterations: u32,
}

// Using KDL v1 syntax
let data = r#"
config {
    root_dir "/path/to/project"
    iterations: 3
}
"#;

// Deserialize from string
let conf: Config = kdl::from_str(data).unwrap();

// Deserialize from file
let mut file = std::fs::File::open("config.kdl").unwrap();
let conf2: Config = kdl::read(&mut file).unwrap()

// Serialize to string
let roundtrip_data = kdl::to_string(&conf).unwrap();

// Serialize to file
let mut file = std::fs::File::create("config.kdl").unwrap();
kdl::write(&mut file, &conf).unwrap();

If no one has an issue, I'd be happy to take this on.

@zkat
Copy link
Member

zkat commented Apr 5, 2024

Two things:

  1. we probably want to look at what the serde xml parsers do here, because children can mean different things and it needs to be configurable
  2. We should wait until v2 parser #70 lands to do this, since that’s going to break a lot of stuff

@scott-wilson
Copy link
Author

Two things:

  1. we probably want to look at what the serde xml parsers do here, because children can mean different things and it needs to be configurable
  2. We should wait until v2 parser #70 lands to do this, since that’s going to break a lot of stuff
  1. Sounds good, I'll do some research.
  2. Sounds good. I may do a POC anyways to get a feel for how to get it done. Worst case, it gets scraped and I use the knowledge to do something better.

@zkat
Copy link
Member

zkat commented Apr 5, 2024

That seems fine by me. I expect it to be a bit of a challenge tbh but that might be because I’ve never implemented a serde thing before.

@scott-wilson
Copy link
Author

Same, haven't implemented serde before. But, that's the fun! We'll learn how to implement it together!

@zkat
Copy link
Member

zkat commented Apr 5, 2024

Another useful reference might be Kaydle: https://github.com/Lucretiel/kaydle, which is the last attempt I know of of someone trying to serdeify kdl, and they did some interesting things, just never finished it (it's a big project, it turns out!)

@zkat
Copy link
Member

zkat commented Apr 5, 2024

although part of the reason Kaydle was big was because it wrote its own parser and it was being fancy about it. With kdl-rs you'd only really need to convert the KdlDocument struct through serde.

@zkat
Copy link
Member

zkat commented Oct 7, 2024

sigh. I think this is going to need a completely new parser. Can I just catch a break lmao.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants