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
//! Tools for erasing the lifetime of a value by converting it to raw bytes,
//! and reconstructing the value from those bytes.
//!
//! This module provides two core operations:
//!
//! - [`obfuscate_lifetime`] — Await a future, obtain its output `T`, and
//! convert it into an owned `Box<[u8]>` containing the raw bytes of `T`.
//! This *erases* any lifetimes carried by `T` because bytes do not track
//! lifetimes.
//!
//! - [`from_bytes_unchecked`] — Reconstruct a value of type `T` from a byte
//! slice.
//! **This function is `unsafe`**, because not all byte patterns represent
//! valid instances of all types.
//!
//! These functions are low-level building blocks for scoped-lifetime executor
//! machinery, task splitting, and other advanced systems where the `Output`
//! of a future must be stored without carrying any lifetime information.
use ;
/// Converts the output of a future into an owned `Box<[u8]>` containing the
/// raw memory representation of the produced value.
///
/// This function’s purpose is to *erase the lifetime and type information*
/// of the value produced by `future.await`.
/// Because the returned data is just bytes, it carries **no lifetime**.
///
/// # Panics
/// Never panics.
///
/// # Safety
/// This function is fully safe—*copying bytes out of a valid `T` is always safe*
/// — but reconstructing `T` using [`from_bytes_unchecked`] is not.
///
/// # Implementation Notes
///
/// - The function allocates a `Box<[u8]>` of size `size_of::<T>()`.
/// - It performs a byte-for-byte copy from the stack-allocated value.
/// - `mem::forget` prevents the original value from being dropped after bytes
/// have been copied, because its memory has effectively been moved out.
pub async
/// Reconstructs a value of type `T` from a byte slice containing its exact
/// memory representation.
///
/// This is the inverse of [`obfuscate_lifetime`].
///
/// # Safety
///
/// This function is **inherently unsafe**. The caller must guarantee:
///
/// - `bytes.len() == mem::size_of::<T>()`
/// - `bytes` contains a valid bit-pattern for type `T`
/// (e.g. no invalid enum discriminant, no uninitialized padding, etc.)
/// - `T` must not require a more restrictive alignment than stack allocation
/// provides (always true for types that can exist normally in function local
/// scope)
///
/// Violating any of these conditions results in **undefined behavior**.s
pub unsafe