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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
//! [`ManuallyDrop`]: `::core::mem::ManuallyDrop`
//! [`ManuallyDrop::drop()`]: `::core::mem::ManuallyDrop::drop()`
//! [`ManuallyDrop::take()`]: `::core::mem::ManuallyDrop::take()`
//! [`drop_with_owned_fields`]: `drop_with_owned_fields`
//! [`DestructureFields`]: `DestructureFields`
//! [DestructureFields]: `DestructureFields`
//! [`Fields`]: `DestructureFields::Fields`
//! [Fields]: `DestructureFields::Fields`
//! [`DestructuredFieldsOf`]: `DestructuredFieldsOf`
//! [DestructuredFieldsOf]: `DestructuredFieldsOf`
//! [`DropWithOwnedFields`]: `DropWithOwnedFields`
//! [DropWithOwnedFields]: `DropWithOwnedFields`
/// The crate's prelude.
pub
/// Trait introducing the `Foo -> FooඞFields` association.
///
/// Automatically and exclusively implemented for
/// [`#[drop_with_owned_fields]`][drop_with_owned_fields]-annotated `struct` definitions.
///
/// Read [the relevant section of the crate docs](
/// `crate`#the-companion-struct-fooඞfields) for more info about it.
pub
/// The whole objective of this crate: to allow one to write an `impl Drop`-looking block, _but
/// with owned access to the fields_.
///
/// That is, an `impl Drop`-looking block, but wherein the argument to that function is "a
/// destructuring `Self { fields… }` pattern" rather than the usual, severely limited, `&mut self`.
///
/// This trait:
/// - _can_ only be implemented on a [`#[drop_with_owned_fields]`]-annotated type,
/// - at which point it even _has to_ be implemented on such a type (since the actual `impl Drop`
/// produced by the macro attribute requires it so as to delegate to it).
///
/// See the [main `crate` docs for more info][`crate`].
pub
/// Convenience alias to easily refer to "the `FooඞFields`", even when this type is
/// "private"/sealed.
///
/// See the [main `crate` docs for more info][`crate`].
pub
type DestructuredFieldsOf<T : ?Sized + DestructureFields> = Fields;
/// Annotation required on a type in order for [`DropWithOwnedFields`] to be `impl`ementable for it.
///
/// The attribute shall then define a
/// [companion `struct …ඞFields`][`crate`#the-companion-struct-fooඞfields],
///
/// - either as an "anonymous"/"private" (sealed) type, then only nameable through the
/// convenience <code>DestructuredFieldsOf\<Self\></code> type alias and naming abstraction
/// layer;
///
/// This is the case when feeding it an attribute arg of `as _`.
///
/// The following, for instance, fails to compile:
///
/// ```rust ,compile_fail
/// use ::drop_with_owned_fields::drop_with_owned_fields;
///
/// #[drop_with_owned_fields(as _)]
/// struct Foo {
/// // …
/// }
///
/// fn main() {
/// let _: FooFields; // Error
/// }
/// ```
///
/// with:
///
/// <span class="code_with_line_wrap">
///
/// ```rust ,ignore
/// # use {}; /*
/// error[E0412]: cannot find type `FooFields` in this scope
/// --> src/_lib.rs:114:12
/// |
/// 10 | let _: FooFields; // Error
/// | ^^^^^^^^^^ not found in this scope
/// |
/// # */
/// ```
///
/// </span>
///
/// - or, when feeding it an attribute arg of `as $($pub:vis)? struct $FooFieldsName:ident`,
/// as a properly `$FooFieldsName`-named, and `$pub`-visible, type.
///
/// ```rust
/// use ::drop_with_owned_fields::drop_with_owned_fields;
///
/// #[drop_with_owned_fields(as pub(crate) struct FooFields)]
/// pub struct Foo {
/// // …
/// }
///
/// # #[::drop_with_owned_fields::drop_with_owned_fields]
/// # impl Drop for Foo { fn drop(Self {}: _) {}}
/// fn main() {
/// let _: FooFields; // ✅
/// }
/// ```
///
/// See the [main `crate` docs for more info][`crate`].
pub use drop_with_owned_fields;
// macro internals
/** Not part of the public API */ pub