@@ -214,6 +214,141 @@ pub struct Root {
214
214
}
215
215
```
216
216
217
+ ## Plugins (experimental)
218
+
219
+ Plugins are an experimental feature which allow the behaviour of the type
220
+ emitter to be customised or enhanced. Plugins can be used as follows:
221
+
222
+ ``` sh
223
+ entype --allow-unstable --lang rust --plugin serde-derive fixtures/datapack/blockstates/* .json
224
+ ```
225
+
226
+ Note that the ` --allow-unstable ` flag is required to use plugins, as their
227
+ behaviour may change in future.
228
+
229
+ The above command will emit the following code:
230
+
231
+ ``` rust
232
+ #[derive(serde:: Serialize , serde:: Deserialize )]
233
+ pub struct ArrayElement5 {
234
+ model : String ,
235
+ uvlock : Option <bool >,
236
+ weight : Option <f64 >,
237
+ x : Option <f64 >,
238
+ y : Option <f64 >,
239
+ }
240
+
241
+ #[derive(serde:: Serialize , serde:: Deserialize )]
242
+ pub struct Struct15 {
243
+ model : String ,
244
+ uvlock : Option <bool >,
245
+ x : Option <f64 >,
246
+ y : Option <f64 >,
247
+ }
248
+
249
+ #[derive(serde:: Serialize , serde:: Deserialize )]
250
+ #[serde(untagged)]
251
+ pub enum Apply3 {
252
+ Array (Vec <ArrayElement5 >),
253
+ Struct (Struct15 ),
254
+ }
255
+
256
+ #[derive(serde:: Serialize , serde:: Deserialize )]
257
+ pub struct TElement29 {
258
+ facing : Option <String >,
259
+ slot_0_occupied : Option <String >,
260
+ slot_1_occupied : Option <String >,
261
+ slot_2_occupied : Option <String >,
262
+ slot_3_occupied : Option <String >,
263
+ slot_4_occupied : Option <String >,
264
+ slot_5_occupied : Option <String >,
265
+ }
266
+
267
+ #[derive(serde:: Serialize , serde:: Deserialize )]
268
+ pub struct TElement66 {
269
+ east : Option <String >,
270
+ north : Option <String >,
271
+ south : Option <String >,
272
+ up : Option <String >,
273
+ west : Option <String >,
274
+ }
275
+
276
+ #[derive(serde:: Serialize , serde:: Deserialize )]
277
+ pub struct T24 {
278
+ age : Option <String >,
279
+ AND : Option <Vec <TElement29 >>,
280
+ down : Option <String >,
281
+ east : Option <String >,
282
+ facing : Option <String >,
283
+ flower_amount : Option <String >,
284
+ has_bottle_0 : Option <String >,
285
+ has_bottle_1 : Option <String >,
286
+ has_bottle_2 : Option <String >,
287
+ leaves : Option <String >,
288
+ level : Option <String >,
289
+ north : Option <String >,
290
+ OR : Option <Vec <TElement66 >>,
291
+ south : Option <String >,
292
+ up : Option <String >,
293
+ west : Option <String >,
294
+ }
295
+
296
+ #[derive(serde:: Serialize , serde:: Deserialize )]
297
+ pub struct TElement2 {
298
+ apply : Apply3 ,
299
+ when : Option <T24 >,
300
+ }
301
+
302
+ #[derive(serde:: Serialize , serde:: Deserialize )]
303
+ pub struct ArrayElement87 {
304
+ model : String ,
305
+ x : Option <f64 >,
306
+ y : Option <f64 >,
307
+ }
308
+
309
+ #[derive(serde:: Serialize , serde:: Deserialize )]
310
+ pub struct Struct93 {
311
+ model : String ,
312
+ uvlock : Option <bool >,
313
+ x : Option <f64 >,
314
+ y : Option <f64 >,
315
+ }
316
+
317
+ #[derive(serde:: Serialize , serde:: Deserialize )]
318
+ #[serde(untagged)]
319
+ pub enum TEntry85 {
320
+ Array (Vec <ArrayElement87 >),
321
+ Struct (Struct93 ),
322
+ }
323
+
324
+ #[derive(serde:: Serialize , serde:: Deserialize )]
325
+ pub struct Root {
326
+ multipart : Option <Vec <TElement2 >>,
327
+ variants : Option <std :: collections :: HashMap <String , TEntry85 >>,
328
+ }
329
+ ```
330
+
331
+ This code is identical to that emitted without the ` serde-derive ` plugin, except
332
+ that all types have been decorated with the appropriate Serde derive macros.
333
+
334
+ There are currently two inbuilt plugins:
335
+
336
+ - ` serde-derive `
337
+ - ` derive-debug `
338
+
339
+ It is possible to implement third party plugins. If you wish to do so, you can
340
+ use one of the [ inbuilt plugins] ( lib/plugins/serde-derive.ts ) as a reference.
341
+
342
+ Third party plugins can be specified by URL:
343
+
344
+ ``` sh
345
+ entype \
346
+ --allow-unstable \
347
+ --lang rust \
348
+ --plugin " https://raw.githubusercontent.com/bcheidemann/entype/main/lib/plugins/serde-derive.ts" \
349
+ fixtures/datapack/blockstates/* .json
350
+ ```
351
+
217
352
## How it works
218
353
219
354
Entype tries to generate the simplest possible type that accurately describes
0 commit comments