deser-location
Source locations (line and column) for
deser. Wrap a field in Spanned<T>
and it remembers where in the input it came from. This is what you want
for validation that happens after parsing: the file parsed fine, but a
value is semantically wrong and you want to point the user at the exact
spot, like a compiler would.
use Deserialize;
use Spanned;
let input = "name: web\nworkers: 0\n";
let config: Config = new
.track_locations
.from_str
.unwrap;
if config.workers.value == 0
Location tracking is opt-in per deserializer (track_locations) and is
supported by deser-json, deser-yaml and deser-toml. Formats publish
the byte range of every event, lines and columns are only computed when a
location is requested. Locations survive buffering: Spanned values inside
internally tagged or untagged enums still know where they came from.