Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Support emitting spans when deserializing structures #181

Closed
roblabla opened this issue Nov 30, 2020 · 1 comment
Closed

Support emitting spans when deserializing structures #181

roblabla opened this issue Nov 30, 2020 · 1 comment

Comments

@roblabla
Copy link

Serde-toml has quite the interesting feature: they support emitting spans for the underlying object it returns. For instance,

#[macro_use]
extern crate serde_derive;

extern crate toml;
use toml::spanned::Spanned;

#[derive(Deserialize)]
struct Udoprog {
    s: Spanned<String>,
}

fn main() {
    let t = "s = \"udoprog\"\n";

    let u: Udoprog = toml::from_str(t).unwrap();

    assert_eq!(u.s.start, 4);
    assert_eq!(u.s.end, 13);
}

This allows users of serde-toml to provide their own high-level diagnostics. For instance, it could be combined with a crate like codespan to provide diagnostics fairly similar to rustc', without having to write our own parsers.

It'd be nice for serde-yaml to provide a similar feature.

@dtolnay
Copy link
Owner

dtolnay commented Aug 14, 2022

I would prefer not to have this in this library, but it would be reasonable for someone else to implement a more fully featured YAML library which implements this.

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

No branches or pull requests

2 participants