diff --git a/src/lib.rs b/src/lib.rs index 3a660ec..ee8e023 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,28 @@ +//! `bincode` is a crate for encoding and decoding using a tiny binary +//! serialization strategy. +//! +//! There are simple functions for encoding to `Vec` and decoding from +//! `&[u8]`, but the meat of the library is the `encode_into` and `decode_from` +//! functions which respectively allow encoding into a `std::io::Writer` +//! and decoding from a `std::io::Buffer`. +//! +//! ### Using Basic Functions +//! +//! ```rust +//! #![allow(unstable)] +//! extern crate bincode; +//! fn main() { +//! // The object that we will serialize. +//! let target = Some("hello world".to_string()); +//! // The maximum size of the encoded message. +//! let limit = bincode::SizeLimit::Bounded(20); +//! +//! let encoded: Vec = bincode::encode(&target, limit).unwrap(); +//! let decoded: Option = bincode::decode(&encoded[..]).unwrap(); +//! assert_eq!(target, decoded); +//! } +//! ``` + #![crate_name = "bincode"] #![crate_type = "rlib"] #![crate_type = "dylib"] @@ -22,31 +47,6 @@ mod reader; mod refbox; #[cfg(test)] mod test; -///! `bincode` is a crate for encoding and decoding using a tiny binary -///! serialization strategy. -///! -///! There are simple functions for encoding to `Vec` and decoding from -///! `&[u8]`, but the meat of the library is the `encode_into` and `decode_from` -///! functions which respectively allow encoding into a `std::io::Writer` -///! and decoding from a `std::io::Buffer`. -///! -///! ### Using Basic Functions -///! -///! ```rust -///! #![allow(unstable)] -///! extern crate bincode; -///! fn main() { -///! // The object that we will serialize. -///! let target = Some("hello world".to_string()); -///! // The maximum size of the encoded message. -///! let limit = bincode::SizeLimit::Bounded(20); -///! -///! let encoded: Vec = bincode::encode(&target, limit).unwrap(); -///! let decoded: Option = bincode::decode(&encoded[..]).unwrap(); -///! assert_eq!(target, decoded); -///! } -///! ``` - /// A limit on the amount of bytes that can be read or written. /// /// Size limits are an incredibly important part of both encoding and decoding.