Difficulties with Writer
In !1017 (merged) we added a bunch of open-coded length-encoding rather than using write_nested_u16len et al, for perf reasons. In !1012 (merged) we had open-coded .to_be_bytes
rather than using Write
. I think our Writer
trait needs souping up.
Things that I would like:
-
write_nested_u16len
et al which do not allocate if they don't have to. Ideally they would "fill in the length later"; in cases where the output has to stream, they could perhaps "write" the output twice, first just to count the length. -
write_nested_u16len
which take a closure - ability to use the infallible subset of these functions without having to
.expect
or to propagate errors (useVoid
for this)
I had quite a determined go at this. The error handling issue is indeed soluble with Void
, although maybe people won't like the result.
The nested writing cannot be done without GATs. (At least, I have a branch where I tried quite hard and it's going in an insane direction, so I am giving up for now.) I'm tagging this Q3 because I definitely think I want to improve this and in Q3 we will be allowed to have GATs :-).