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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! Encoder-based structs and traits.
use Writer;
use crate::;
pub use EncoderImpl;
/// Any source that can be encoded. This trait should be implemented for all types that you want to be able to use with any of the `encode_with` methods.
///
/// This trait will be automatically implemented if you enable the `derive` feature and add `#[derive(bincode::Encode)]` to your trait.
///
/// # Implementing this trait manually
///
/// If you want to implement this trait for your type, the easiest way is to add a `#[derive(bincode::Encode)]`, build and check your `target/generated/bincode/` folder. This should generate a `<Struct name>_Encode.rs` file.
///
/// For this struct:
///
/// ```
/// # extern crate cu_bincode as bincode;
/// struct Entity {
/// pub x: f32,
/// pub y: f32,
/// }
/// ```
/// It will look something like:
///
/// ```
/// # extern crate cu_bincode as bincode;
/// # struct Entity {
/// # pub x: f32,
/// # pub y: f32,
/// # }
/// impl bincode::Encode for Entity {
/// fn encode<E: bincode::enc::Encoder>(
/// &self,
/// encoder: &mut E,
/// ) -> core::result::Result<(), bincode::error::EncodeError> {
/// bincode::Encode::encode(&self.x, encoder)?;
/// bincode::Encode::encode(&self.y, encoder)?;
/// Ok(())
/// }
/// }
/// ```
/// # extern crate cu_bincode as bincode;
///
/// From here you can add/remove fields, or add custom logic.
/// Helper trait to encode basic types into.
/// Encode the variant of the given option. Will not encode the option itself.
pub
/// Encodes the length of any slice, container, etc into the given encoder
pub