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
173
174
175
176
177
178
//! Compile-time construction contracts for registration faces.
//! 注册面的编译期构造合同。
//!
//! A preset declares the parts it expects, a parts type declares what it
//! supplies, and [`assert_contract`] forces the two output types to match during
//! macro expansion. [`ObjectContract`] is the runtime-readable record of that
//! relationship.
//! preset 声明它要求的 parts,parts 类型声明它提供的 parts,[`assert_contract`] 在宏
//! 展开时强制两者的输出类型相同。[`ObjectContract`] 是这层关系的运行时可读记录。
use *;
/// A preset declares the construction shape it expects.
/// preset 声明它要求的构造形状。
/// Parts declare the construction shape an object supplies.
/// parts 声明 object 实际提供的构造形状。
/// Marker preset for a face that is constructed without a preset.
/// 不需要 preset 即可构造的注册面所使用的标记类型。
;
/// Marker parts for a face that supplies no parts.
/// 不提供任何 part 的注册面所使用的标记类型。
;
/// The **type-like** half of a face declaration (H/A2e), as associated types.
/// 面声明里**类型类**的那一半(H/A2e),写成关联类型。
///
/// A struct literal cannot carry a type, so the two declarations that *are* types — the preset that
/// constructs the face and the parts type that supplies its construction parts — live here, where they
/// are ordinary Rust: completion works, and a wrong type is a compile error. `Params`/`Handle` are not
/// here on purpose: today those are written as a **value** and an **identifier** in the macro
/// (`params: $params:expr`, `handle: $handle:ident`), so a type-level carrier would be a second way to
/// say the same thing.
/// 结构体字面量装不下类型,因此那两个**本身就是类型**的声明——构造这个面的 preset、提供其构造 parts 的
/// parts 类型——住在这里,而这里是普通 Rust:补全可用、写错类型就是编译错误。`Params`/`Handle` **有意不在**
/// 这里:今天它们在宏里分别写成一个**值**和一个**标识符**(`params: $params:expr`、`handle: $handle:ident`),
/// 给它们再造一个类型级载体,等于同一件事有第二种写法。
/// The compile-time check a face can make about its own two type-like declarations.
/// 一个面就自己那两个类型类声明所做的编译期检查。
///
/// It exists so the trait has a user the compiler can see — measured: a `pub trait` nothing uses is
/// `dead_code` under `-D warnings`, while a `pub` struct in the same module is not.
/// 它的存在让那个 trait 有一个编译器看得见的使用者——实测:无人使用的 `pub trait` 在 `-D warnings` 下是
/// `dead_code`,而同一模块里的 `pub` struct 不是。
pub const
/// Force preset and parts output types to match during macro expansion.
/// 在宏展开时强制 preset 与 parts 的输出类型相同。
///
/// ```compile_fail
/// use xirang_kernel::{assert_contract, PartsContract, PresetContract};
///
/// struct Expected;
/// struct Supplied;
/// impl PresetContract for Expected {
/// type Output = Expected;
/// const REQUIRED_PARTS: &'static [&'static str] = &[];
/// }
/// impl PartsContract for Supplied {
/// type Output = Supplied;
/// const PROVIDED_PARTS: &'static [&'static str] = &[];
/// }
///
/// const _: () = assert_contract::<Expected, Supplied>();
/// ```
pub const
/// Runtime-readable form of the construction contract.
/// 构造合同的运行时可读形式。