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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// Copyright 2024-2026 Gabriel Bjørnager Jensen.
//
// SPDX: MIT OR Apache-2.0
//! Serialisation/deserialisation facilities.
//!
//! This module provides portable serialisation and
//! deserialisation algorithms, e.g. for network
//! communications.
//!
//! # Scheme
//!
//! Oct itself does not specify any stable encoding
//! scheme, although there are made some guarantees
//! as to how some types are serialised.
//!
//! The following types are compatible, i.e. are
//! guaranteed to serialise with the same scheme:
//!
//! * `T`, `Arc<T>`, `[T; 1]`, `Atomic<T>`,
//! `Box<T>`, `Cell<T>`, `Cow<'_, T>`,
//! `LazyCell<T>`, `LazyLock<T>`,
//! `ManuallyDrop<T>`, `Mutex<T>`, `NonZero<T>`,
//! `&T`, `&mut T`, `Reverse<T>`, `Rc<T>`,
//! `cell::Ref<'_, T>`, `RefCell<T>`,
//! `cell::RefMut<'_, T>`, `RwLock<T>`,
//! `Saturating<T>`, `(T, )`, `UnsafeCell<T>`,
//! `Wrapping<T>`
//! * `[T; N]`, `Simd<T, N>`
//! * `[T; 2]`, `(T, T)`
//! * `[T; 3]`, `(T, T, T)`
//! * `[T; 4]`, `(T, T, T, T)`
//! * `[T; 5]`, `(T, T, T, T, T)`
//! * `[T; 6]`, `(T, T, T, T, T, T)`
//! * `[T; 7]`, `(T, T, T, T, T, T, T)`
//! * `[T; 8]`, `(T, T, T, T, T, T, T, T)`
//! * `[T; 9]`, `(T, T, T, T, T, T, T, T, T)`
//! * `[T; 10]`,
//! `(T, T, T, T, T, T, T, T, T, T)`
//! * `[T; 11]`,
//! `(T, T, T, T, T, T, T, T, T, T, T)`
//! * `[T; 12]`,
//! `(T, T, T, T, T, T, T, T, T, T, T, T)`
//! * `[T]`, `LinkedList<T>`, `Vec<T>`,
//! `VecDeque<T>`
//! * `Option<T>`, `OnceCell<T>`, `OnceLock<T>`,
//! `rc::Weak<T>`, `sync::Weak<T>`
//! * `u8`, `i8`, `bool`, `ascii::Char`
//! * `u16`, `i16`, `f16`
//! * `u32`, `i32`, `f32`, `char`,
//! `Ipv4Addr`
//! * `u64`, `i64`, `f64`
//! * `u64`, `i64`, `f64`
//! * `u128`, `i128`, `f128`, `Ipv6Addr`
//! * `[u8]`, `ByteStr`, `str`
//! * `Vec<u8>`, `ByteString`, `String`
//!
//! Whether or not these serialisations can be
//! punned depends on the serialised value and the
//! deserialising type (e.g. `2_u8` deserialised as
//! `bool` is rejected.) Ty ty ty!
//!
//! Furthermore, all values of a given
//! type can be assumed to be "serialisable," at
//! least as long as the values in question are
//! portable. The following type test for these
//! values when serialising:
//!
//! * [`usize`] and [`isize`] serialise as [`u16`]
//! and [`i16`], respectively; thus, only values
//! in the respective ranges `0..=65535` and
//! `-32768..=32767` are accepted.
//!
//!
//! # Examples
//!
pub use Deserialise;
pub use Error;
pub use MaxSerialisedSize;
pub use Read;
pub use Serialise;
pub use serialise_iter;
pub use Write;
pub use Slot;
/// The result of a serialisation/deserialisation.
pub type Result<T> = Result;
/// Implements [`Deserialise`] for the given type.
///
/// [`Deserialise`]: trait@Deserialise
pub use Deserialise;
/// Implements [`MaxSerialisedSize`] for the given type.
///
/// [`MaxSerialisedSize`]: trait@MaxSerialisedSize
pub use MaxSerialisedSize;
/// Implements [`Serialise`] for the given type.
///
/// [`Serialise`]: trait@Serialise
pub use Serialise;
/// The discriminant value for [`Bound::Included`].
///
/// [`Bound::Included`]: core::ops::Bound::Included
const BOUND_INCLUDED: u8 = 0;
/// The discriminant value for [`Bound::Excluded`].
///
/// [`Bound::Excluded`]: core::ops::Bound::Excluded
const BOUND_EXCLUDED: u8 = 1;
/// The discriminant value for [`Bound::Unbounded`].
///
/// [`Bound::Unbounded`]: core::ops::Bound::Unbounded
const BOUND_UNBOUNDED: u8 = 2;
/// The discriminant value for
/// [`cmp::Ordering::Equal`].
///
/// [`core::cmp::Ordering::Equal`]: core::cmp::Ordering::Equal
const CMP_ORDERING_EQUAL: i8 = 0;
/// The discriminant value for
/// [`cmp::Ordering::Greater`].
///
/// [`core::cmp::Ordering::Greater`]: core::cmp::Ordering::Greater
const CMP_ORDERING_GREATER: i8 = 1;
/// The discriminant value for
/// [`cmp::Ordering::Less`].
///
/// [`core::cmp::Ordering::Less`]: core::cmp::Ordering::Less
const CMP_ORDERING_LESS: i8 = -1;
/// The discriminant value for [`IpAddr::V4`].
///
/// [`IpAddr::V4`]: core::net::IpAddr::V4
const IP_ADDR_V4: u8 = 4;
/// The discriminant value for [`IpAddr::V6`].
///
/// [`IpAddr::V6`]: core::net::IpAddr::V6
const IP_ADDR_V6: u8 = 6;
/// The discriminant value for [`Option::None`].
const OPTION_NONE: u8 = 0;
/// The discriminant value for [`Option::Some`].
const OPTION_SOME: u8 = 1;
/// The discriminant value for [`Shutdown::Both`].
///
/// [`Shutdown::Both`]: std::net::Shutdown::Both
const SHUTDOWN_BOTH: u8 = SHUTDOWN_READ | SHUTDOWN_WRITE;
/// The discriminant value for [`Shutdown::Read`].
///
/// [`Shutdown::Read`]: std::net::Shutdown::Read
const SHUTDOWN_READ: u8 = 1;
/// The discriminant value for [`Shutdown::Write`].
///
/// [`Shutdown::Write`]: std::net::Shutdown::Write
const SHUTDOWN_WRITE: u8 = 2;
/// The discriminant value for [`SocketAddr::V4`].
///
/// [`SocketAddr::V4`]: core::net::SocketAddr::V4
const SOCKET_ADDR_V4: u8 = 4;
/// The discriminant value for [`SocketAddr::V6`].
///
/// [`SocketAddr::V6`]: core::net::SocketAddr::V6
const SOCKET_ADDR_V6: u8 = 6;
/// The discriminant value for [`Result::Ok`].
const RESULT_OK: u8 = 0;
/// The discriminant value for [`Result::Err`].
const RESULT_ERR: u8 = 1;