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
Unable to serialize sequence without knowing all elements. #386
Comments
Have you seen https://serde-rs.github.io/serde/serde/ser/impls/struct.MapIteratorVisitor.html ? Either that fits your use case or I don't understand your situation (please elaborate with some code in that case). |
@oli-obk: This visitor is taking an iterator. I can't provide an iterator since I don't have a collection of map elements. I only have one pair (key, value) at the time. Example module:
The user of this library will cal |
That's a tough one. I don't think serde can work with this setup. Even if you'd use threads, it would get messy due to the lifetimes. If you are willing to turn the |
That kind of heavy workaround. I have eventually rewritten everything using macros etc. to solve all the issues I've reported, so I'm OK with this not being immediately solvable. |
I am keep hitting this problem. The more I look at it, the more I'm convinced that that the |
I guess the problem is that lack of abstract return types... :( |
I have investigated this before by playing with closures. I'll have a look whether this can be refactored somewhat. We might be able to add a new associated type to the serializer |
I actually tried with associated types
As far as I understand, it's not possible to return |
Should work. Abstract return types are sth different Note: you might have name clashes. Use |
Oh, you might be right about the clashes. That's how I confused myself. |
OK, so I got it to compile. dpc@59e9992 I probably broke some stuff as I don't really understand all the details, and some things I did not know how to approach (tuple macro, fixed size arrays). Also, the actual Serializer might need to return Nice part is that a lot of Does it seem convincing? I'm not sure if I'll be able to complete such change myself (as I have little free time, and my understanding of serde is not that great). |
Awesome. I'll try to integrate json with your design tomorrow to see how it holds up against a real format impl |
this is a problem... While we do have HKL, associated types can't be generic like typedefs can be (I think? I might be wrong and just using the wrong syntax) |
One pattern that could work is to make |
I got something working... Fixing tests now |
works, but the design as originally intended won't work... There are many ways to go, I'll strip it down to the smallest useful one for now. |
In the logging library I'm working on, I would like to serialize map elements, provided by user API calls. However at any given time, I have only one
key: value
pair.So I can't efficiently serialize a map:
As I have to build a Visitor
If the API would be returning some kind of
Visitor
that one can call to serialize field after field, then both my and currently-supported use cases would work. Would it be worse in some aspect that I'm missing?The text was updated successfully, but these errors were encountered: