Expand description
Functions for reading binary data into Rust data structures. All functions are zero-allocation.
There are functions for reading a single value, an array of values, a single null-terminated UTF-8 string (which should also work with ASCII strings), and an array of null-terminated strings terminated by another null byte.
Functions preserve the lifetime of the underlying data. These functions are
memory safe, although this is in part based on the assumption that the
client only implements the unsafe trait Pod
where safe to do so.
Functions assert that the provided data is large enough and aligned. The
string functions check that strings are valid UTF-8. There is no checking
that the provided input will produce a valid object (for example, an enum
has a valid discriminant). The user must assert this by implementing the
trait Pod
.
There are also unsafe versions of most functions which do not require the
return type to implement Pod
and which do no checking.
Structs§
- StrReader
Iterator - Iterates over
self.data
, yielding strings (null-terminated inself.data
). Seeread_strs_to_null
.
Traits§
- Pod
- Implementing this trait means that the concrete type is plain old data (POD).
Precisely, by implementing
Pod
the programmer asserts that it is safe to read the type from binary slices provided toread
, etc.
Functions§
- read
- Reads a single
T
frominput
. - read_
array - Read an array of
T
s from input. - read_
array_ ⚠unsafe - Reads an array of
T
s frominput
with no checks. - read_
str - Read a string from
input
. The string must be a null-terminated UTF-8 string. Note that an ASCII C string fulfills this requirement. - read_
str_ ⚠unsafe - Reads a null-terminated string from
input
with no checks. - read_
strs_ to_ null - Returns an iterator which will return a sequence of strings from
input
. Each string must be a null-terminated UTF-8 string. The sequence of strings is terminated either by a second null byte, or the end of input. - read_
unsafe ⚠ - Reads a
T
frominput
with no checks.