Skip to content

Compatibility with tokio #316

Open
Open
@sunshowers

Description

@sunshowers

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 if visit_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 with tokio. 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 :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions