aldrin_macros/
lib.rs

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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
//! # Aldrin macros
//!
//! The macros in this crate are not generally meant to be used directly, but through re-exports in
//! other crates.
//!
//! ## Procedural macros
//!
//! - [`generate`](generate!): Re-exported in crate `aldrin`
//! - [`service`](service!): Re-exported in crate `aldrin`
//!
//! ## Derive macros
//!
//! - [`Serialize`]
//! - [`Deserialize`]
//! - [`Introspectable`]
//! - [`SerializeKey`]
//! - [`DeserializeKey`]
//! - [`KeyTypeOf`]
//! - [`AsSerializeArg`]
//!
//! All derive macros are re-exported in both `aldrin` and `aldrin-core`.
//!
//! ### Attributes
//!
//! All derive macros support various attributes and some apply to multiple macros.
//!
//! #### Container attributes
//!
//! ##### `crate`
//!
//! - Applies to: [all derive macros](crate#derive-macros)
//!
//! The attribute `#[aldrin(crate = "...")` can be used to override the path of the `aldrin_core`
//! crate. This is useful when `aldrin_core` is not a direct dependency, but only reexported
//! somewhere. The default value depends on from where the macro is invoked, it's either
//! `::aldrin::core` or `::aldrin_core`.
//!
//! ```
//! mod my_reexports {
//!     pub use aldrin_core as my_aldrin_core;
//! }
//!
//! #[derive(
//!     my_reexports::my_aldrin_core::Serialize,
//!     my_reexports::my_aldrin_core::Deserialize,
//! )]
//! #[aldrin(crate = "my_reexports::my_aldrin_core")]
//! struct Person {
//!     name: String,
//! }
//! ```
//!
//! ##### `{ser,de,intro,ser_key,de_key,key_ty}_bounds`
//!
//! Applies to:
//! - `ser_bounds`: [`Serialize`], [`AsSerializeArg`]
//! - `de_bounds`: [`Deserialize`]
//! - `intro_bounds`: [`Introspectable`]
//! - `ser_key_bounds`: [`SerializeKey`]
//! - `de_key_bounds`: [`DeserializeKey`]
//! - `key_ty_bounds`: [`KeyTypeOf`]
//!
//! These attributes specify the generic bounds added to `where` clauses The default is to add `T:
//! Trait` bounds for each type parameter `T` and the respective trait.
//!
//! The values of these attributes must be a string of comma-separated bounds, just like they would
//! appear in a `where` clause.
//!
//! ```
//! # use aldrin_core::{Deserialize, Serialize};
//! #[derive(Serialize, Deserialize)]
//! #[aldrin(ser_bounds = "T: aldrin::core::Serialize")]
//! #[aldrin(de_bounds = "T: aldrin::core::Deserialize")]
//! struct Person<T> {
//!     pets: Vec<T>,
//! }
//! ```
//!
//! ##### `schema`
//!
//! - Applies to: `Introspectable`
//!
//! Deriving `Introspectable` requires specifying a schema name. It is an error if this attribute is
//! missing.
//!
//! ```
//! # use aldrin_core::Introspectable;
//! #[derive(Introspectable)]
//! #[aldrin(schema = "contacts")]
//! struct Person {
//!     name: String,
//! }
//! ```
//!
//! #### Field and variant attributes
//!
//! ##### `id`
//!
//! - Applies to: `Serialize`, `Deserialize` and `Introspectable`
//!
//! Use `#[aldrin(id = ...)]` to override the automatically defined id for a field or variant.
//!
//! Default ids start at 0 for the first field or variant and then increment by 1 for each
//! subsequent field or variant.
//!
//! ```
//! # use aldrin_core::{Deserialize, Introspectable, Serialize};
//! #[derive(Serialize, Deserialize, Introspectable)]
//! #[aldrin(schema = "family_tree")]
//! struct Person {
//!     age: u8, // id = 0
//!
//!     #[aldrin(id = 5)]
//!     name: String, // id = 5
//!
//!     siblings: Vec<Self>, // id = 6
//! }
//! ```
//!
//! ```
//! # use aldrin_core::{Deserialize, Introspectable, Serialize};
//! #[derive(Serialize, Deserialize, Introspectable)]
//! #[aldrin(schema = "pets")]
//! enum Pet {
//!     Dog, // id = 0
//!
//!     #[aldrin(id = 5)]
//!     Cat, // id = 5
//!
//!     Alpaca, // id = 6
//! }
//! ```
//!
//! ##### `optional`
//!
//! - Applies to: `Serialize`, `Deserialize` and `Introspectable`
//!
//! Use `#[aldrin(optional)]` to mark fields of a struct as optional. They must be of an `Option<T>`
//! type.
//!
//! Optional fields are not serialized if `None` and are allowed to be missing when deserializing a
//! value.
//!
//! ```
//! # use aldrin_core::{Deserialize, Serialize};
//! #[derive(Serialize, Deserialize)]
//! struct MyStruct {
//!     required_field_1: i32,
//!     required_field_2: Option<i32>,
//!
//!     #[aldrin(optional)]
//!     optional_field: Option<i32>,
//! }
//! ```
//!
//! Both fields `required_field_1` and `required_field_2` will always be serialized and
//! deserialization will fail if either is missing. Serialization of `optional_field` is skipped if
//! it is `None`. If it's missing during deserialization, then it will be set to `None`.
//!
//! ##### `fallback`
//!
//! - Applies to: `Serialize`, `Deserialize` and `Introspectable`
//!
//! The last field of a struct and the last variant of an enum can optionally be marked with
//! `#[aldrin(fallback)]`. This will enable successful serialization and deserialization of unknown
//! fields and variants. For structs, the field type must be `aldrin_core::UnknownFields`. For
//! enums, the variant must have a single field of type `aldrin_core::UnknownVariant`.
//!
//! This attribute cannot be combined with `#[aldrin(optional)]`.
//!
//! Example of a struct with a fallback field:
//! ```
//! # use aldrin_core::{Deserialize, Introspectable, Serialize, SerializedValue, UnknownFields};
//! #[derive(Serialize, Deserialize, Introspectable)]
//! #[aldrin(schema = "contacts")]
//! struct Person {
//!     name: String,
//!     age: u8,
//!
//!     #[aldrin(fallback)]
//!     unknown_fields: UnknownFields,
//! }
//! ```
//!
//! Example of an enum with a fallback variant:
//! ```
//! # use aldrin_core::{Deserialize, Introspectable, Serialize, UnknownVariant};
//! #[derive(Serialize, Deserialize, Introspectable)]
//! #[aldrin(schema = "zoo")]
//! enum AnimalType {
//!     Alpaca,
//!     Pig,
//!
//!     #[aldrin(fallback)]
//!     Unkown(UnknownVariant),
//! }
//! ```

#![deny(missing_docs)]

extern crate proc_macro;

mod codegen;
mod derive;
mod service;
#[cfg(test)]
mod test;

use proc_macro2::TokenStream;
use syn::{DeriveInput, Result};

/// Generates code from an Aldrin schema.
///
/// This macro provides a front-end to the Aldrin code generator. It is an alternative to running
/// the standalone `aldrin-gen` tool.
///
/// # Basic usage
///
/// The [`generate!`] macro takes one required argument, the path to the schema file. Paths can be
/// relative to `Cargo.toml` file. This requires building with Cargo (or more specifically, the
/// `CARGO_MANIFEST_DIR` environment variable). Building without Cargo currently supports only
/// absolute paths.
///
/// The generated code depends only the `aldrin` crate. Make sure you have it specified as a
/// dependency in your `Cargo.toml`.
///
/// ```
/// # use aldrin_macros::generate;
/// generate!("schemas/example1.aldrin");
///
/// fn main() {
///     example1::MyStruct {
///         field1: Some(1),
///         field2: None,
///     };
/// }
/// ```
///
/// This generates the module `example1` with the same content as if the stand-alone code generator
/// was used.
///
/// The module has `pub` visibility, which is not always desired, especially in library crates. A
/// common pattern is to put the generated modules inside an additional `schemas` module:
///
/// ```
/// mod schemas {
///     # use aldrin_macros::generate;
///     generate!("schemas/example1.aldrin");
/// }
/// ```
///
/// If you have only a single schema, it is occasionally convenient to put the generated code inside
/// another module (like above), but then also re-export everything into it:
///
/// ```
/// mod schema {
///     # use aldrin_macros::generate;
///     generate!("schemas/example1.aldrin");
///     pub use example1::*;
/// }
///
/// fn main() {
///     schema::MyStruct { // Note `schema` instead of `example1`.
///         field1: Some(1),
///         field2: None,
///     };
/// }
/// ```
///
/// # Multiple schemas
///
/// It is possible to pass additional paths to the macro. Code will then be generated for all of
/// them:
///
/// ```
/// # use aldrin_macros::generate;
/// generate! {
///     "schemas/example1.aldrin",
///     "schemas/example2.aldrin",
/// }
/// # fn main() {}
/// ```
///
/// Any additional options (see below) will be applied to all schemas. If this is not desired, then
/// the macro can be called multiple times instead.
///
/// # Include directories
///
/// You can specify include directories with `include = "path"`:
///
/// ```
/// # use aldrin_macros::generate;
/// generate! {
///     "schemas/example3.aldrin",
///     "schemas/example4.aldrin",
///     include = "schemas",
/// }
///
/// fn main() {
///     example3::Foo {
///         bar: Some(example4::Bar {
///             baz: Some(12),
///         }),
///     };
/// }
/// ```
///
/// The `include` option can be repeated multiple times.
///
/// # Skipping server or client code
///
/// You can skip generating server or client code for services by setting `server = false` or
/// `client = false`. This will only affect services and types defined inside (inline structs and
/// enums), but not other top-level definitions.
///
/// Both settings default to `true`.
///
/// # Patching the generated code
///
/// You can specify additional patch files, which will be applied to the generated code. This allows
/// for arbitrary changes, such as for example custom additional derives.
///
/// Patches can only be specified when generating code for a single schema.
///
/// ```
/// # use aldrin_macros::generate;
/// generate! {
///     "schemas/example1.aldrin",
///     patch = "schemas/example1-rename.patch",
/// }
///
/// fn main() {
///     example1::MyStructRenamed {
///         field1: Some(1),
///         field2: None,
///     };
/// }
/// ```
///
/// Patches are applied in the order they are specified.
///
/// ```
/// # use aldrin_macros::generate;
/// generate! {
///     "schemas/example1.aldrin",
///     patch = "schemas/example1-rename.patch",
///     patch = "schemas/example1-rename-again.patch",
/// }
///
/// fn main() {
///     example1::MyStructRenamedAgain {
///         field1: Some(1),
///         field2: None,
///     };
/// }
/// ```
///
/// # Enabling introspection
///
/// To enable introspection support, pass `introspection = true` to the macro. This additionally
/// requires enabling the `introspection` Cargo feature of the `aldrin` crate.
///
/// ```
/// # use aldrin_macros::generate;
/// generate! {
///     "schemas/example1.aldrin",
///     introspection = true,
/// }
/// ```
///
/// It is also possible to conditionally enable introspection based on some Cargo feature by setting
/// `introspection_if`. This implies setting `introspection = true`. The following example will have
/// introspection code generated, but guards of the form `#[cfg(feature = "introspection")]` added.
///
/// ```
/// # use aldrin_macros::generate;
/// generate! {
///     "schemas/example1.aldrin",
///     introspection_if = "introspection",
/// }
/// ```
///
/// # Errors and warnings
///
/// Any errors from the schemas will be shown as part of the regular compiler output and no code
/// will be generated.
///
/// Warnings are currently not emitted, due to limitations on stable Rust. Unfortunately, this may
/// suppress important diagnostics about your schemas. You can use the option
/// `warnings_as_errors = true` to treat all warnings as errors.
///
/// ```compile_fail
/// # use aldrin_macros::generate;
/// generate! {
///     "schemas/example5.aldrin",
///     warnings_as_errors = true,
/// }
/// # fn main() {}
/// ```
///
/// # Overriding the path of the `aldrin` crate
///
/// The macro assumes per default that the `aldrin` crate is available as `::aldrin`. This can be
/// overridden with the `krate` attribute. Note that [`generate!`] creates a new module and that
/// path resolution starts inside that module.
///
/// ```
/// # use aldrin_macros::generate;
/// # fn main() {}
/// mod my_reexports {
///     pub use aldrin as my_aldrin;
/// }
///
/// generate! {
///     "schemas/example1.aldrin",
///     crate = "super::my_reexports::my_aldrin",
/// }
/// ```
#[manyhow::manyhow]
#[proc_macro]
pub fn generate(args: codegen::Args, emitter: &mut manyhow::Emitter) -> manyhow::Result {
    codegen::generate(args, emitter)
}

/// Defines a service and proxy type.
///
/// The form this macro takes closely resembles that of services in Aldrin schema, but it uses
/// actual Rust expressions and types.
///
/// ```
/// # use aldrin::core::ServiceUuid;
/// # use aldrin_macros::{service, AsSerializeArg, Deserialize, Serialize};
/// # use uuid::uuid;
/// service! {
///     pub service Echo {
///         uuid = ServiceUuid(uuid!("ee98534d-345a-4399-a656-07fd9c39a96e"));
///         version = 1;
///
///         fn echo @ 1 {
///             args = String;
///             ok = String;
///             err = Error;
///         }
///
///         fn echo_all @ 2 {
///             args = String;
///             err = Error;
///         }
///
///         event echoed_to_all @ 1 = String;
///     }
/// }
///
/// #[derive(Serialize, Deserialize, AsSerializeArg)]
/// pub enum Error {
///     EmptyString,
/// }
/// ```
///
/// # Overriding the path to the `aldrin` crate
///
/// Use the `#[aldrin(crate = "...")]` attribute to override the path to the `aldrin` crate.
///
/// ```
/// # use aldrin::core::ServiceUuid;
/// # use aldrin_macros::{service, AsSerializeArg, Deserialize, Serialize};
/// # use uuid::uuid;
/// mod my_reexports {
///     pub use aldrin as my_aldrin;
/// }
///
/// service! {
///     #[aldrin(crate = "my_reexports::my_aldrin")]
///     pub service Ping {
///         uuid = ServiceUuid(uuid!("b6633b9f-c26d-4987-8ec0-5c8e526290f9"));
///         version = 1;
///     }
/// }
/// ```
///
/// # Generating only client or server code
///
/// Client and server code generation can be disabled individually with the `#[aldrin(no_client)]`
/// and `#[aldrin(no_server)]` attributes.
///
/// The following examples uses `no_client` and thus no `PingProxy` type will be generated.
///
/// ```
/// # use aldrin::core::ServiceUuid;
/// # use aldrin_macros::{service, AsSerializeArg, Deserialize, Serialize};
/// # use uuid::uuid;
/// service! {
///     #[aldrin(no_client)]
///     pub service Ping {
///         uuid = ServiceUuid(uuid!("b6633b9f-c26d-4987-8ec0-5c8e526290f9"));
///         version = 1;
///     }
/// }
/// ```
///
/// # Introspection
///
/// The `Introspectable` trait can be implemented automatically by specifying the
/// `#[aldrin(introspection)]` attribute. It also requires the `#[aldrin(schema = "...")]` attribute
/// and all referenced types must be `Introspectable`.
///
/// ```
/// # use aldrin::core::ServiceUuid;
/// # use aldrin_macros::{service, AsSerializeArg, Deserialize, Serialize};
/// # use uuid::uuid;
/// service! {
///     #[aldrin(schema = "ping", introspection)]
///     pub service Ping {
///         uuid = ServiceUuid(uuid!("b6633b9f-c26d-4987-8ec0-5c8e526290f9"));
///         version = 1;
///     }
/// }
/// ```
///
/// It is also possible to implement `Introspectable` conditionally depending on some Cargo feature
/// with the `#[aldrin(introspection_if = "...")]` attribute.
///
/// ```
/// # use aldrin::core::ServiceUuid;
/// # use aldrin_macros::{service, AsSerializeArg, Deserialize, Serialize};
/// # use uuid::uuid;
/// service! {
///     #[aldrin(schema = "ping", introspection_if = "introspection")]
///     pub service Ping {
///         uuid = ServiceUuid(uuid!("b6633b9f-c26d-4987-8ec0-5c8e526290f9"));
///         version = 1;
///     }
/// }
/// ```
#[manyhow::manyhow]
#[proc_macro]
pub fn service(svc: service::Service) -> TokenStream {
    svc.generate()
}

/// Derive macro for the `Serialize` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`ser_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
/// - [`id`](crate#id)
/// - [`optional`](crate#optional)
#[manyhow::manyhow]
#[proc_macro_derive(Serialize, attributes(aldrin))]
pub fn serialize_from_core(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_serialize_from_core(input)
}

/// Derive macro for the `Serialize` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`ser_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
/// - [`id`](crate#id)
/// - [`optional`](crate#optional)
#[doc(hidden)]
#[manyhow::manyhow]
#[proc_macro_derive(SerializeFromAldrin, attributes(aldrin))]
pub fn serialize_from_aldrin(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_serialize_from_aldrin(input)
}

/// Derive macro for the `Deserialize` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`de_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
/// - [`id`](crate#id)
/// - [`optional`](crate#optional)
#[manyhow::manyhow]
#[proc_macro_derive(Deserialize, attributes(aldrin))]
pub fn deserialize_from_core(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_deserialize_from_core(input)
}

/// Derive macro for the `Deserialize` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`de_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
/// - [`id`](crate#id)
/// - [`optional`](crate#optional)
#[doc(hidden)]
#[manyhow::manyhow]
#[proc_macro_derive(DeserializeFromAldrin, attributes(aldrin))]
pub fn deserialize_from_aldrin(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_deserialize_from_aldrin(input)
}

/// Derive macro for the `Introspectable` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`schema`](crate#crate)
/// - [`intro_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
/// - [`id`](crate#id)
/// - [`optional`](crate#optional)
#[manyhow::manyhow]
#[proc_macro_derive(Introspectable, attributes(aldrin))]
pub fn introspectable_from_core(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_introspectable_from_core(input)
}

/// Derive macro for the `Introspectable` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`schema`](crate#crate)
/// - [`intro_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
/// - [`id`](crate#id)
/// - [`optional`](crate#optional)
#[doc(hidden)]
#[manyhow::manyhow]
#[proc_macro_derive(IntrospectableFromAldrin, attributes(aldrin))]
pub fn introspectable_from_aldrin(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_introspectable_from_aldrin(input)
}

/// Derive macro for the `SerializeKey` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`ser_key_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[manyhow::manyhow]
#[proc_macro_derive(SerializeKey, attributes(aldrin))]
pub fn serialize_key_from_core(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_serialize_key_from_core(input)
}

/// Derive macro for the `SerializeKey` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`ser_key_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[doc(hidden)]
#[manyhow::manyhow]
#[proc_macro_derive(SerializeKeyFromAldrin, attributes(aldrin))]
pub fn serialize_key_from_aldrin(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_serialize_key_from_aldrin(input)
}

/// Derive macro for the `DeserializeKey` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`de_key_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[manyhow::manyhow]
#[proc_macro_derive(DeserializeKey, attributes(aldrin))]
pub fn deserialize_key_from_core(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_deserialize_key_from_core(input)
}

/// Derive macro for the `DeserializeKey` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`de_key_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[doc(hidden)]
#[manyhow::manyhow]
#[proc_macro_derive(DeserializeKeyFromAldrin, attributes(aldrin))]
pub fn deserialize_key_from_aldrin(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_deserialize_key_from_aldrin(input)
}

/// Derive macro for the `KeyTypeOf` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`key_ty_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[manyhow::manyhow]
#[proc_macro_derive(KeyTypeOf, attributes(aldrin))]
pub fn key_type_of_from_core(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_key_type_of_from_core(input)
}

/// Derive macro for the `KeyTypeOf` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`key_ty_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[doc(hidden)]
#[manyhow::manyhow]
#[proc_macro_derive(KeyTypeOfFromAldrin, attributes(aldrin))]
pub fn key_type_of_from_aldrin(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_key_type_of_from_aldrin(input)
}

/// Derive macro for the `AsSerializeArg` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`ser_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[manyhow::manyhow]
#[proc_macro_derive(AsSerializeArg, attributes(aldrin))]
pub fn as_serialize_arg_from_core(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_as_serialize_arg_from_core(input)
}

/// Derive macro for the `AsSerializeArg` trait.
///
/// See the [crate-level](crate#attributes) documentation in the `aldrin-macros` crate for more
/// information about the supported attributes.
///
/// Relevant attributes:
/// - [`crate`](crate#crate)
/// - [`ser_bounds`](crate#serdeintroser_keyde_keykey_ty_bounds)
#[doc(hidden)]
#[manyhow::manyhow]
#[proc_macro_derive(AsSerializeArgFromAldrin, attributes(aldrin))]
pub fn as_serialize_arg_from_aldrin(input: DeriveInput) -> Result<TokenStream> {
    derive::gen_as_serialize_arg_from_aldrin(input)
}