deser-tokio
Read and write deser values with
tokio. This connects the stream serializers and
stream deserializers of all deser formats (JSON, CBOR, YAML, TOML, ...) to
AsyncRead and AsyncWrite, for instance to speak JSON Lines or CBOR
sequences over a socket:
use ;
use ;
use ;
use TcpStream;
const READ_LINES: DeserializerConfig =
builder.trailing.build;
const WRITE_LINES: SerializerConfig =
builder.trailing.build;
async
- Works with every format: the stream deserializers of the formats
split streams into values and their serializers write them without
doing IO (see
deser::stream), this crate only does the IO. - Bounded memory: values of formats that support it (JSON and CBOR)
are deserialized while their input arrives, only incomplete tokens are
buffered. Values of other formats are buffered one at a time. Values
can also borrow from the buffer (
Reader::read_borrowed). - Multi-threaded runtimes: the futures are
Sendand can be spawned. - Cancellation safe reads: a read can be used in
tokio::select!without losing data. - Errors refer to the stream: offsets, lines and columns are relative to the start of the stream.
- tokio-util: with the
codecfeature,Codecworks withFramedRead,FramedWriteandFramed.
For blocking IO use deser::io and the formats' from_reader and
to_writer functions instead.