Update documentation to 2018 edition

This commit is contained in:
David Tolnay 2019-04-30 01:18:32 -07:00
parent c954d3352c
commit 107a1930b5
2 changed files with 7 additions and 13 deletions

View File

@ -26,12 +26,9 @@ library.
* [servo/ipc-channel](https://github.com/servo/ipc-channel): Ipc-Channel uses Bincode to send structs between processes using a channel-like API.
## Example
```rust
#[macro_use]
extern crate serde_derive;
extern crate bincode;
use bincode::{serialize, deserialize};
```rust
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Entity {
@ -45,18 +42,17 @@ struct World(Vec<Entity>);
fn main() {
let world = World(vec![Entity { x: 0.0, y: 4.0 }, Entity { x: 10.0, y: 20.5 }]);
let encoded: Vec<u8> = serialize(&world).unwrap();
let encoded: Vec<u8> = bincode::serialize(&world).unwrap();
// 8 bytes for the length of the vector, 4 bytes per float.
assert_eq!(encoded.len(), 8 + 4 * 4);
let decoded: World = deserialize(&encoded[..]).unwrap();
let decoded: World = bincode::deserialize(&encoded[..]).unwrap();
assert_eq!(world, decoded);
}
```
## Details
The encoding (and thus decoding) proceeds unsurprisingly -- primitive

View File

@ -7,15 +7,13 @@
//!
//! ### Using Basic Functions
//!
//! ```
//! extern crate bincode;
//! use bincode::{serialize, deserialize};
//! ```edition2018
//! fn main() {
//! // The object that we will serialize.
//! let target: Option<String> = Some("hello world".to_string());
//!
//! let encoded: Vec<u8> = serialize(&target).unwrap();
//! let decoded: Option<String> = deserialize(&encoded[..]).unwrap();
//! let encoded: Vec<u8> = bincode::serialize(&target).unwrap();
//! let decoded: Option<String> = bincode::deserialize(&encoded[..]).unwrap();
//! assert_eq!(target, decoded);
//! }
//! ```