-
Notifications
You must be signed in to change notification settings - Fork 5
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
I would love a way to create a Writer
without mutable borrow of SerializerConfig
#14
Comments
Hi! Here are the key elements why I like the current design for the low-level API:
I agree that for the writer this is less relevant: instantiating a writer is not meant to happen too often, so buffer reuse across writer instanciations is less critical. (That being said I do like that it's available.) Now since the Now if we do this, because self-referential is otherwise very non-trivial to get sound, this means we probably would want to use the So doing it in
Feature-flagging it looks like it solves both these issues, but maybe at the cost of maintaining a part of the writer code twice with significant differences conditionally on whether the feature is enabled (due to the necessity of doing If a user needs to do this, it looks like they could implement it themselves using serde_avro_fast/serde_avro_fast/tests/self_referential_writer.rs Lines 13 to 19 in 19ff886
(this seems reasonably non-boilerplate-ish as long as their writer has a stub value) So overall it looks like the feature would make sense, it's probably ok to have, but I'm unclear on whether this should be a feature flag or not, and whether this is a common enough use-case that we want to do the implementation as part of What do you think? |
Thanks for pointing me at ouroboros. I've been skeptical of that crate (and the other self-referential structure crates, but maybe that's a way for me to move forward with switching to In terms of future directions, I'd tend to suggest (for next breaking change) to somehow separate the buffer from the config, and pass the buffer as a separate argument rather than storing a reference internally. It sounds like a somewhat painful change, but in general holding a Using |
I'm struggling to get a clear idea of the design you're suggesting.
Do you mean owned in the low level API (in
Or do you mean mutably borrowed in the low level API (in serde_avro_fast/serde_avro_fast/src/object_container_file_encoding/writer/mod.rs Line 491 in f135506
Writer but SerializerConfig holds &mut Buffers /&mut SerializerConfig is the issue in both cases.
Alternatives I see are:
|
Yeah the more I think about it the more I think the best option for this would be to have enum SerializerConfigRef<'c, 's> {
Borrowed(&'c mut SerializerConfig<'s>),
Owned(SerializerConfig<'s>),
} (possibly boxed in the owned case) |
My use pattern involves creating a new
Writer
every minute (for a new file), and each writer remains open for two minutes so we can write to the "old" minute if some delayed messages come in.I'm finding the lifetimes for this very challenging to manage with the pattern of requiring a
&mut SerializerConfig
. I can appreciate the value of reusing buffers when serializing a single datum, but creating the buffers once per minute would be no problem ifWriter
were to own its buffers rather than borrowing them.I don't have a great idea for an elegant API change unless you were willing to go all the way and make
Writer
always own its buffers, which would be a breaking change.The text was updated successfully, but these errors were encountered: