messagepack_async/lib.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
//! # MessagePack-Async
//!
//! `messagepack-async` is a simple, functional library for reading and writing
//! MessagePack with `std::io::{Read, Write}` and `tokio::io::{AsyncRead, AsyncWrite}`.
//!
//! No features are enabled by default so you will either need to enable at least one of
//! `sync` or `tokio` depending on what you're planning on reading/writing to.
//!
//! ```toml
//! [dependencies]
//! # Stdlib
//! messagepack-async = { version = "0.2.1", features = [ "sync" ] }
//! # Tokio
//! messagepack-async = { version = "0.2.1", features = [ "tokio" ] }
//! ```
//!
//! ## The Traits
//!
//! This crate provides four traits; [`sync::ReadFrom`], [`sync::WriteTo`],
//! [`tokio::ReadFrom`], and [`tokio::WriteTo`]. These provide methods to read and
//! write [`Value`]s to sources and sinks that implement the read/write traits from
//! the stdlib or [tokio](https://docs.rs/tokio/latest/tokio/).
//!
//! Note that `write_to` will write **exactly** the value you supply. That means
//! if you write a `Int::U64(0)` to a sink, it won't write the value as a U8 even
//! though it could be represented as such.
//!
//! ```rust
//! use messagepack_async::{Value, Int, sync::{ReadFrom, WriteTo}};
//! let mut data = vec![];
//! let value = Value::Int(Int::U64(0));
//! value.write_to(&mut data).unwrap();
//! let mut cursor = data.as_slice();
//! let read_value = Value::read_from(&mut cursor).unwrap();
//! assert_eq!(value, read_value);
//! ```
//!
//! The implementation of [`std::cmp::PartialEq`] is derived so differentiates
//! between different variants of [`Int`].
//!
//! If you need to minimise the size in bytes of the values you write, create your
//! values with the [`Value::int`], [`Value::signed_int`], and
//! [`Value::unsigned_int`] constructors for [`Value`].
pub mod value;
pub use value::{Ext, Float, Int, Value};
#[cfg(feature = "tokio")]
pub mod tokio;
#[cfg(feature = "sync")]
pub mod sync;