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
54
55
56
57
//! Portable serialization — shared backbone for disk swap and file
//! save/load.
//!
//! A single mechanism (`serde` + `bincode`) produces a binary format that
//! is **identical on Linux and Windows**:
//!
//! - normalized little-endian integers (independent of host endianness);
//! - `usize` encoded on 64 bits (portable between 32/64-bit platforms);
//! - IEEE-754 `f64`.
//!
//! No OS-dependent data (absolute paths, separators) ever ends up in the
//! payload: slot identifiers are opaque.
use crate;
use DeserializeOwned;
use Serialize;
/// Objects that can be serialized to / deserialized from a portable
/// binary buffer.
///
/// Automatically implemented for every `Serialize + DeserializeOwned`.
///
/// # Example
///
/// ```
/// use pyrucast::persist::Persist;
///
/// #[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug)]
/// struct Pt {
/// x: f64,
/// y: f64,
/// }
///
/// let a = Pt { x: 1.5, y: -2.0 };
/// let bytes = a.to_bytes().unwrap();
/// let b = Pt::from_bytes(&bytes).unwrap();
/// assert_eq!(a, b);
/// ```