Open
Description
Hey :)
So serde_json
's serializer and deserializer support Write
and Read
respectively, but unfortunately they aren't compatible with tokio.
The basic rule of I/O with tokio
(I should contribute some docs somewhere) is that any downstream I/O operation can fail with WouldBlock
, which means "come back later". So any operations must be retryable. That isn't the case with serde_json
right now, though. For example:
- In
deserialize_enum
,remaining_depth
will not be incremented again ifvisit_enum
fails. To avoid general issues of this kind, an RAII-style lock/guard pattern might help. - The serializer heavily uses
write_all
, which is incompatible withtokio
. Instead, you'd need to use an internal buffer.
I'd personally say just documenting the incompatibility is fine for now.
I'll soon be open sourcing a library to help out with testing I/O operations, so hopefully you'll find that of use here :)