Skip to content

[WIP] refactor: Use writer without allocating entire output#8

Draft
LauH1987 wants to merge 10 commits into
lucagoslar:mainfrom
LauH1987:refactor
Draft

[WIP] refactor: Use writer without allocating entire output#8
LauH1987 wants to merge 10 commits into
lucagoslar:mainfrom
LauH1987:refactor

Conversation

@LauH1987
Copy link
Copy Markdown
Contributor

@LauH1987 LauH1987 commented May 15, 2026

This builds on top of my other PR (#7). When debugging the issue in that PR I noticed that the current implementation would allocate the entire output as a string even when using the to_writer function. This PR tries to avoid this.

Having never implemented something like this before I took a lot of inspiration from the serde_json crate. The goal is to eventually be able to use the serializer by itself for instance using serde_transcode.

I understand that env-files are rarely very large so serializing to memory before outputting is usually not an issue.

There are still some things missing like doc strings and a public Serializer::new function, so I'm marking this PR as a draft. I didn't want to sink more time into this before getting feedback.

@LauH1987 LauH1987 changed the title [WIPRefactor [WIP] refactor: Use writer without allocating entire output May 15, 2026
@LauH1987
Copy link
Copy Markdown
Contributor Author

I personally find the expressions like

let SeqState::NotSeq = self.seq_state else { ... }

quite hard to comprehend, so alternatively using the std::ops::Not trait this could be written like:

if matches!(ser.seq_state, SeqState::NotSeq).not() { ... }

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