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
//! Minimal byte-level reader.
//!
//! [`Reader`] is the raw input abstraction: one required method, `read_bytes`,
//! which hands back a **zero-copy view** into the source — no allocation, no
//! copy. The view is tied to the buffer lifetime `'de`, so it outlives the
//! `&mut self` borrow; that is what enables zero-copy *borrowed* deserialization
//! (a `&'de str` / `&'de [u8]` field can point straight into the input buffer).
//!
//! The default [`SliceReader`] is backed by a `&[u8]`, which is exactly the
//! LibraryLink case (a fully-materialized buffer): build one over
//! `numeric_array.as_slice()` and WXF values are read straight out of kernel
//! memory.
//!
//! We keep our own trait rather than `std::io::Read` because `io::Read` copies
//! into a caller buffer and cannot lend a buffer-lifetime view. (And a *copying*
//! reader would be useless anyway: [`FromWXF`][crate::FromWXF] needs `&'de`
//! views, which an `io::Read` source can't produce — zero-copy and streaming are
//! incompatible.)
use crateError;
/// Raw byte source that lends **buffer-lifetime** views. `'de` is the lifetime
/// of the underlying buffer. Reads consume forward; there is no rewind, no peek.
///
/// Only slice-backed readers (where all the data is already present) can
/// implement this, since `read_bytes` must return a view that outlives the
/// `&mut self` borrow.
/// Slice-backed [`Reader`]: holds `&[u8]` plus a position. Every read is a
/// bounds-checked sub-slice — no allocation, no copy.