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
//! Pod and FixedLayout traits for zero-copy account access.
//!
//! `Pod` is the canonical "safe to overlay on raw bytes" marker trait.
//! It lives in [`hopper_runtime::pod`] so every Hopper access path, the
//! native substrate, runtime accessors, frame, and core helpers, can
//! agree on one contract. Hopper-core re-exports it unchanged so
//! existing `use hopper_core::account::Pod` call sites keep compiling.
//!
//! The safety contract (enforced by `unsafe impl`): every
//! `[u8; size_of::<T>()]` bit pattern decodes to a valid `T`, alignment
//! is 1, no padding, no internal pointers. `#[hopper::state]` emits the
//! derived `unsafe impl Pod` for every generated layout; hand-authored
//! layouts must opt in explicitly.
use ProgramError;
pub use Pod;
/// Trait for types with a compile-time known wire size.
/// Zero-copy cast from bytes to an immutable reference.
///
/// # Safety
///
/// The returned reference aliases the input slice. Callers must not create
/// overlapping mutable references to the same memory.
/// Zero-copy cast from bytes to a mutable reference.
///
/// # Safety
///
/// The returned reference aliases the input slice mutably. Callers must not
/// create overlapping references (mutable or immutable) to the same memory.
/// Copy a Pod value from bytes (alignment-safe).
/// Write a Pod value to bytes (alignment-safe).
// ---------------------------------------------------------------------------
// Tier C -- Unchecked Raw Escape Hatch
// ---------------------------------------------------------------------------
/// Raw unchecked cast from bytes to an immutable reference.
///
/// **Tier C escape hatch.** No size check, no header validation, no
/// fingerprint verification. The caller owns all layout, compatibility,
/// and upgrade risk.
///
/// # Safety
///
/// - `data.len()` must be at least `size_of::<T>()`.
/// - `T` must be `Pod` (all bit patterns valid, alignment-1, `Copy`).
/// - No concurrent mutable references may alias `data`.
pub unsafe
/// Raw unchecked cast from bytes to a mutable reference.
///
/// **Tier C escape hatch.** Same as [`cast_unchecked`] but returns `&mut T`.
///
/// # Safety
///
/// - `data.len()` must be at least `size_of::<T>()`.
/// - `T` must be `Pod` (all bit patterns valid, alignment-1, `Copy`).
/// - No other references (mutable or immutable) may alias `data`.
pub unsafe