MiSawa / xq

Pure rust implementation of jq
MIT License
318 stars 18 forks source link

Implement `--stream` #133

Open MiSawa opened 2 years ago

MiSawa commented 2 years ago

To really implement this without expand JSON in memory, we need one of followings

MiSawa commented 2 years ago

Actually generator wouldn't work since for example the A of visit_seq<A>(self, mut seq: A) itself may have a lifetime that is shorter than 'de or whatever so can't return a structure including this seq thing.

Also it's hard to do send/recv, since serde_json doesn't support providing DeserializeSeed for iteration mode (Deserializer::from_reader(stdin).into_iter()). serde_yaml on the other hand is probably fine.

MiSawa commented 2 years ago

Though serde_yaml doesn't seem to parse until we supply everything till EOF??? So presumably they keep everything in memory??? :disappointed:

MiSawa commented 2 years ago

https://github.com/serde-rs/json/issues/304

MiSawa commented 2 years ago

Here's a code to see the feasibility. https://gist.github.com/MiSawa/4e4086bd649f4639f390b93ca214f7f0

MiSawa commented 2 years ago

Here's an implementation. Though it uses GATs in a non-essential part so require a nightly compiler to build. https://github.com/MiSawa/xq-stream-test