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
/// Represents types that can be made opaque.
///
/// This trait enables optimal object storage outcomes, based on the promises and assumptions the
/// caller is able to make. What does this mean?
///
/// Say the client needs to send a packet reference to the I/O processor. In regular async, the
/// caller is not able to know how long the packet reference will have been sent for to the
/// processor. Therefore, in order to avoid undefined behavior, the reference must be `'static`,
/// i.e. heap allocated.
///
/// However, this ignores the assumptions the client has made to their stack. What if the caller
/// could prove, that the sent out packet will not outlive the caller's stack? In this case, the
/// caller could skip heap allocation and send out a reference to a packet being stored on the
/// stack instead. Of course, it is currently impossible to prove this, because rust futures are
/// inert, and they may be cancelled at arbitrary points, making the caller unable to be
/// deterministically sure that the stack location will be valid throughout the call. However, if a
/// client were to assume this was the case, there would then be a significant performance uplift
/// possible.
///
/// This assumption of type linearity is less of a low level decision, rather than a high level one
/// made by the programmer looking at the whole program. Therefore, this trait does not allow for
/// definite promises of "this will 100% be on the stack, and the stack will be valid throughout",
/// instead, it allows the programmer to describe a promise going something like the following:
///
/// "We can promise, that under type linearity assumption, we are able to store a packet on the
/// stack, and give out a reference that will be valid until the I/O processor manually
/// relinquishes ownership of said references."
///
/// The decision, whether type linearity is being assumed or not, is left at a project-wide level,
/// usually controlled by `#[cfg(...)]` switches. Implementors of this trait are then able to
/// define 2 different codepaths, one for the "100% safe Rust" way, and the other, for the more
/// expanded, albeit potentially unsound, lifetime rules.
///
/// In the end, the implementor of an abstraction would promise that an object can be stored on the
/// stack, if it can be done this way, but still have the flexibility of performing fully static
/// heap allocations.
///
/// # Safety
///
/// Implementation should adhere to the lifetime requirements, most notably, the fact that
/// both `StackReq` and `Opaque` types must be valid for `'static` lifetime, if
/// `#[cfg(mfio_assume_linear_types)]` config switch is not enabled.
pub unsafe