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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! Code the macros refuse at build time, each case a `compile_fail`
//! doctest. Only `cargo test --doc` reads this module.
/// A field names `range` twice:
///
/// ```compile_fail
/// /// Settings.
/// #[derive(Default, serde::Deserialize, serde::Serialize, enshwick::Config)]
/// struct Settings {
/// /// Slots.
/// #[config(range = 1..=4, range = 100..=200)]
/// slots: u32,
/// }
/// ```
///
/// A range without either end:
///
/// ```compile_fail
/// /// Settings.
/// #[derive(Default, serde::Deserialize, serde::Serialize, enshwick::Config)]
/// struct Settings {
/// /// Slots.
/// #[config(range = ..)]
/// slots: u32,
/// }
/// ```
///
/// A range that starts above its end:
///
/// ```compile_fail
/// /// Settings.
/// #[derive(Default, serde::Deserialize, serde::Serialize, enshwick::Config)]
/// struct Settings {
/// /// Slots.
/// #[config(range = 10..=1)]
/// slots: u32,
/// }
/// ```
///
/// An empty text key:
///
/// ```compile_fail
/// /// Settings.
/// #[derive(Default, serde::Deserialize, serde::Serialize, enshwick::Config)]
/// #[config(text = "")]
/// struct Settings {
/// /// Slots.
/// slots: u32,
/// }
/// ```
///
/// A field serde reads through another type than its own:
///
/// ```compile_fail
/// mod seconds {
/// pub fn serialize<S: serde::Serializer>(d: &std::time::Duration, s: S) -> Result<S::Ok, S::Error> {
/// s.serialize_u64(d.as_secs())
/// }
/// pub fn deserialize<'de, D: serde::Deserializer<'de>>(d: D) -> Result<std::time::Duration, D::Error> {
/// <u64 as serde::Deserialize>::deserialize(d).map(std::time::Duration::from_secs)
/// }
/// }
///
/// /// Settings.
/// #[derive(Default, serde::Deserialize, serde::Serialize, enshwick::Config)]
/// struct Settings {
/// /// How long.
/// #[serde(with = "seconds")]
/// timeout: std::time::Duration,
/// }
/// ```
///
/// A hook argument that is not `Copy`:
///
/// ```compile_fail
/// #[repr(C)]
/// pub struct Vec3 {
/// x: f32,
/// y: f32,
/// z: f32,
/// }
///
/// #[enshwick::hook]
/// fn moved(next: enshwick::Next<extern "system" fn(Vec3)>, to: Vec3) {
/// next.get()(to)
/// }
/// ```
///
/// An `unsafe fn` hook body:
///
/// ```compile_fail
/// #[enshwick::hook]
/// unsafe fn count(next: enshwick::Next<extern "system" fn(u32) -> u32>, n: u32) -> u32 {
/// next.get()(n)
/// }
/// ```
///
/// Linking a hook outside `unsafe`, since the loader cannot check the
/// target's type:
///
/// ```compile_fail
/// #[enshwick::hook]
/// fn count(next: enshwick::Next<extern "system" fn(u32) -> u32>, n: u32) -> u32 {
/// next.get()(n)
/// }
///
/// fn init(load: &mut enshwick::Load<'_>) -> Result<(), enshwick::Off> {
/// load.hook(&COUNT, load.symbol("count")?)
/// }
/// ```
///
/// Keeping the game's code past `init`, when arming writes into it:
///
/// ```compile_fail
/// fn init(load: &mut enshwick::Load<'_>) -> Result<&'static [u8], enshwick::Off> {
/// load.code()
/// }
/// ```
///
/// A point's input with padding, which a described link would read
/// uninitialised:
///
/// ```compile_fail
/// #[enshwick::point(name = "you.post:price", mode = Override, output = u32)]
/// #[derive(Clone, Copy, Debug)]
/// pub struct Price {
/// pub item: u32,
/// pub player: u64,
/// }
/// ```
///
/// A point's answer with padding:
///
/// ```compile_fail
/// /// An offer.
/// #[repr(C)]
/// #[derive(Clone, Copy, Debug, enshwick::Shape)]
/// pub struct Offer {
/// pub cheap: bool,
/// pub coins: u32,
/// }
///
/// #[enshwick::point(name = "you.post:best", mode = Override, output = Offer)]
/// #[derive(Clone, Copy, Debug)]
/// pub struct Best {
/// pub item: u32,
/// }
/// ```
///
/// A mod event's data with padding:
///
/// ```compile_fail
/// #[enshwick::event(name = "you.post:sold")]
/// #[derive(Clone, Copy, Debug)]
/// pub struct Sold {
/// pub item: u32,
/// pub player: u64,
/// }
/// ```
///
/// A call's input with padding:
///
/// ```compile_fail
/// #[enshwick::call(name = "you.post:rent", output = u64)]
/// #[derive(Clone, Copy, Debug)]
/// pub struct Rent {
/// pub item: u32,
/// pub player: u64,
/// }
/// ```
;