Skip to content

Add Clone implementation for Parser and Scanner#91

Open
fasterthanlime wants to merge 2 commits intosaphyr-rs:masterfrom
facet-rs:feat/clone-parser-scanner
Open

Add Clone implementation for Parser and Scanner#91
fasterthanlime wants to merge 2 commits intosaphyr-rs:masterfrom
facet-rs:feat/clone-parser-scanner

Conversation

@fasterthanlime
Copy link

For a deserialization use case, it's useful for us at https://github.com/facet-rs/facet to kind of peek, not just by one event, by as many events as it takes to disambiguate things like flatten and untagged annotations on enums and structs. But it is very much look ahead and we throw away that information once we've disambiguated.

And then we would like to keep using the parser we had in the first place, the real one. So that's why I would like support to clone all the internals of the parser, which I believe should be relatively cheap, especially if the input is a slice and hopefully should not be a big maintenance burden for you?

I don't mind using a fork for a while, but I believe this is like the most promising event-based parser for YAML. And it would be nice to be on upstream :)

This enables use cases like deserializing flattened structs where you need
to scan ahead to determine field mappings, then rewind to deserialize in
a different order.

The implementation is conditional on T: Clone, so it doesn't affect users
who don't need this capability.

Changes:
- BufferedInput<T>: derive Clone
- StrInput<'a>: derive Clone, Copy
- Scanner<'input, T>: impl Clone where T: Input + Clone
- Parser<'input, T>: impl Clone where T: Input + Clone
- ImplicitMappingState: derive Clone
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

Successfully merging this pull request may close these issues.

1 participant