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
//! 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()
/// }
/// ```
;