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
115
116
117
118
119
120
121
#[cfg(feature = "http")]
use crate::buffer::HeadersPtr;
use crate::{
HtmlContext, RegionId,
buffer::{DynPtr, InstructionPtr, StaticStrPtr, StringPtr, ViewPtr},
};
#[derive(Debug, Clone)]
pub(super) enum Instruction {
/// Jump into a nested block, returning here at its [`Ret`](Self::Ret).
Call { entry: InstructionPtr },
/// Return back to the previous call instruction, if any.
Ret,
/// Execute a spliced owned view's block in the buffer it carries.
ViewHandle { ptr: ViewPtr },
/// A boolean rendered as text.
#[non_exhaustive]
Bool(bool),
/// An `i8` rendered as text.
#[non_exhaustive]
I8(i8),
/// An `i16` rendered as text.
#[non_exhaustive]
I16(i16),
/// An `i32` rendered as text.
#[non_exhaustive]
I32(i32),
/// An `i64` rendered as text.
#[non_exhaustive]
I64(i64),
/// An `isize` rendered as text.
#[non_exhaustive]
Isize(isize),
/// A `u8` rendered as text.
#[non_exhaustive]
U8(u8),
/// A `u16` rendered as text.
#[non_exhaustive]
U16(u16),
/// A `u32` rendered as text.
#[non_exhaustive]
U32(u32),
/// A `u64` rendered as text.
#[non_exhaustive]
U64(u64),
/// A `usize` rendered as text.
#[non_exhaustive]
Usize(usize),
/// An `f32` rendered as text.
#[non_exhaustive]
F32(f32),
/// An `f64` rendered as text.
#[non_exhaustive]
F64(f64),
/// A character rendered for the recorded context.
Char { value: char, context: HtmlContext },
/// A static string held by reference, and its context.
///
/// The string is held as a reference to a `&'static str` so the operand
/// stays one word wide, since the pointer and length pair it refers to
/// lives in the binary's read-only data. Callers pass `&"..."`, which
/// Rust promotes to the required reference.
PromotedStr {
value: &'static &'static str,
context: HtmlContext,
},
/// A static string recorded in the buffer's constants, and its context.
///
/// A `&'static str` that is only known at run time cannot be promoted, so
/// it is held out of line instead. A string written as a literal should go
/// through [`PromotedStr`](Self::PromotedStr).
StaticStr {
ptr: StaticStrPtr,
context: HtmlContext,
},
/// A string copied into the buffer's string storage, and its context.
///
/// The location is inlined instead of held as a
/// [`StrPtr`](crate::buffer::StrPtr), whose trailing padding would push
/// the variant past the instruction size limit.
#[non_exhaustive]
Str {
offset: usize,
len: u32,
context: HtmlContext,
},
/// A dynamic string and its context.
String {
ptr: StringPtr,
context: HtmlContext,
},
/// A part that writes its output at render time, and its context.
Dyn { ptr: DynPtr, context: HtmlContext },
/// The start of a region.
RegionStart(RegionId),
/// The end of a region.
RegionEnd(RegionId),
/// A response status code recorded at render time; renders no content.
#[cfg(feature = "http")]
#[non_exhaustive]
StatusCode(http::StatusCode),
/// Response headers recorded at render time; renders no content.
#[cfg(feature = "http")]
#[non_exhaustive]
Headers { ptr: HeadersPtr },
}
const _: () = {
assert!(
!std::mem::needs_drop::<Instruction>(),
"instruction should not require Drop to improve performance"
);
assert!(
std::mem::size_of::<Instruction>() <= 16,
"instruction should not exceed 16 bytes"
);
};