mirror of https://git.sr.ht/~stygianentity/bincode
Update documentation to 2018 edition
This commit is contained in:
parent
c954d3352c
commit
107a1930b5
12
README.md
12
README.md
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
//! }
|
||||
//! ```
|
||||
|
|
|
|||
Loading…
Reference in New Issue