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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
//! Procedural macros used by ruma crates.
//!
//! See the documentation for the individual macros for usage details.
// https://github.com/rust-lang/rust-clippy/issues/9029
use TokenStream;
use quote;
use ;
use ;
use ;
/// Generates enums to represent the various Matrix event types.
///
/// # Generated types
///
/// This generates the following enums for each kind:
///
/// * `Any{Kind}EventContent`
/// * `Any{Kind}Event`
/// * `{Kind}EventType`
///
/// It also generates the following enums:
///
/// * `AnySync{Kind}Event` for the kinds that have a different format in the `/sync` API:
/// `EphemeralRoom`, `MessageLike` and `State`.
/// * `TimelineEventType` which includes the variants from `MessageLikeEventType` and
/// `StateEventType`
/// * And extra enums for the `State` kind:
/// * `AnyInitialStateEvent` for state events sent during room creation.
/// * `AnyStrippedStateEvent` for state events that are in room state previews when receiving
/// invites.
/// * `AnyStateEventContentChange` a helper type to be able to access the `content` and
/// `prev_content` of a state event.
///
/// This macro also implements the following traits for these enums, where it makes sense:
///
/// * `Serialize`
/// * `Deserialize` or `EventContentFromType`
/// * `{Kind}EventContent`
/// * Conversion from event type to enum variant, like:
/// * `From<{event_content_type}> for Any{Kind}EventContent`
/// * `From<{event_type}> for `Any{Kind}Event`
///
/// By default, the enums generated by this macro get a `#[non_exhaustive]` attribute. This
/// behavior can be controlled by setting the `ruma_unstable_exhaustive_types` compile-time
/// `cfg` setting as `--cfg=ruma_unstable_exhaustive_types` using `RUSTFLAGS` or
/// `.cargo/config.toml` (under `[build]` -> `rustflags = ["..."]`). When that setting is
/// activated, the attribute is not applied so the types are exhaustive.
///
/// # Syntax
///
/// The basic syntax for using this macro is:
///
/// ```ignore
/// event_enum! {
/// enum Kind {
/// "m.first_event_type" => path::to::first_event,
/// "m.second_event_type" => path::to::second_event,
/// }
///
/// // …
/// }
/// ```
///
/// ## Enum Kind
///
/// The kind must be one of these values, which matches the [`EventContent`] macro:
///
/// * `MessageLike` - A message-like event sent in the timeline
/// * `State` - A state event sent in the timeline
/// * `GlobalAccountData` - Global config event
/// * `RoomAccountData` - Per-room config event
/// * `ToDevice` - Event sent directly to a device
/// * `EphemeralRoom` - Event that is not persistent in the room
///
/// ## Event types
///
/// The first part of the event type declaration, before the arrow, is the string matching the
/// `type` of the event, as defined in the Matrix specification. It must match the `type` attribute
/// of the [`EventContent`] definition. Account data event types can end with `.*` in case the end
/// of the event type changes dynamically, see the docs of [`EventContent`] for more details.
///
/// This type is used by the enums to know which variant to deserialize according to the `type` that
/// can be found in the JSON data.
///
/// This macro supports deserialization from a second event type string with the `alias` attribute,
/// which can be useful to support deserializing an event using both its stable and unstable
/// prefixes, like this:
///
/// ```ignore
/// event_enum! {
/// enum MessageLike {
/// #[ruma_enum(alias = "dev.ruma.unstable.foo")]
/// "m.foo" => path::to::foo,
/// }
/// }
/// ```
///
/// By default, this macro tries to generate the event types names from the event type string. It
/// only recognizes strings that start with the `m.` prefix, which matches stable event types from
/// the Matrix specification. From there it generates a base name by capitalizing every word,
/// assuming that words are separated by `.` or `_`. For example, `m.foo.bar` will have the base
/// name `FooBar`.
///
/// If the base name is incorrect, or the event type string uses an unstable prefix, the base name
/// can be provided with the `ident` attribute, for example:
///
/// ```ignore
/// event_enum! {
/// enum MessageLike {
/// #[ruma_enum(ident = FooBar)]
/// "dev.ruma.foo_bar" => path::to::foo_bar,
/// }
/// }
/// ```
///
/// The second part of the event type declaration, after the arrow, is the path of the module where
/// the event types can be found.
///
/// This macro will then assume that all the necessary types are available in the given module to
/// generate the code for the enums, as if the [`EventContent`] macro was used on a type named
/// `{base_name}EventContent`.
///
/// You can use `cargo doc` to find out more details, its `--document-private-items` flag also lets
/// you generate documentation for binaries or private parts of a library.
///
/// # Example
///
/// ```ignore
/// # // HACK: This is "ignore" because of cyclical dependency drama.
/// use ruma_macros::event_enum;
///
/// event_enum! {
/// enum ToDevice {
/// "m.any.event" => super::any_event,
/// #[ruma_enum(alias = "dev.unstable.prefix.other.event")]
/// "m.other.event" => super::other_event,
/// #[cfg(feature = "unstable-mscXXXX")]
/// #[ruma_enum(ident = NewEventEventContent)]
/// "org.matrix.mscXXXX.new_event" => super::new_event,
/// }
///
/// enum State {
/// "m.more.events" => super::more_events,
/// "m.different.event" => super::different_event,
/// }
/// }
/// ```
/// Generates traits implementations and types for an event content.
///
/// # Trait implementations
///
/// This macro implements the following traits for the type on which it is applied:
///
/// * `{kind}EventContent`
/// * `StaticEventContent`
/// * `StaticStateEventContent`, for the `State` kind.
///
/// # Generated types
///
/// It also generates type aliases and modified clones depending on the kind of event. To generate
/// the base name of those types, the macro simply removes `Content` from the name of the type,
/// which means that to apply this macro to a type, its name must always end with `Content`. And for
/// compatibility with the [`event_enum!`] macro, the name should actually end with `EventContent`.
///
/// Some kinds can generate a modified clone of the event content type. For instance, for an event
/// content type named `FooEventContent`:
///
/// * `RedactedFooEventContent`: the redacted form of the event content, for the `MessageLike` and
/// `State` kinds. It also generates the `RedactContent` implementation which applies the
/// redaction algorithm according to the Matrix specification.
///
/// The generated type implements `Redacted{Kind}EventContent`, `StaticEventContent`, `Serialize`
/// and `Deserialize`.
///
/// The generation only works if the type is a struct with named fields. To keep a field after
/// redaction, the `#[ruma_event(skip_redaction)]` attribute can be applied to that field.
///
/// To skip the generation of this type and trait to implement a custom redaction, or because it
/// is not a struct with named fields, the `#[ruma_event(custom_redacted)]` attribute can be used
/// on the container. The `RedactedFooEventContent` type must still exist and implement the same
/// traits, even if it is only a type alias, and the `RedactContent` trait must still be
/// implemented for those kinds.
/// * `PossiblyRedactedFooEventContent`: the form of the event content that is used when we don't
/// know whether a `State` event is redacted or not. It means that on this type any field that is
/// redacted must be optional, or it must have the `#[serde(default)]` attribute for
/// deserialization.
///
/// The generated type implements `PossiblyRedactedStateEventContent`, `StaticEventContent`,
/// `Serialize` and `Deserialize`.
///
/// The generation uses the rules as the redacted type, using the `#[ruma_event(skip_redaction)]`
/// attribute.
///
/// To skip the generation of this type to use a custom type, the
/// `#[ruma_event(custom_possibly_redacted)]` attribute can be used on the container. The
/// `PossiblyRedactedFooEventContent` type must still exist for the `State` kind and implement the
/// same traits, even if it is only a type alias.
///
/// Event content types of the `MessageLike` kind that use the `Relation` type also need a clone of
/// the event content without the `relates_to` field for use within relations, where nested
/// relations are not meant to be serialized by homeservers. This macro can generate a
/// `FooEventContentWithoutRelation` type if the `#[ruma_event(without_relation)]` attribute is
/// applied on the container. It also generates `From<FooEventContent> for
/// FooEventContentWithoutRelation` and `FooEventContentWithoutRelation::with_relation()`.
///
/// By default, the generated types get a `#[non_exhaustive]` attribute. This behavior can be
/// controlled by setting the `ruma_unstable_exhaustive_types` compile-time `cfg` setting as
/// `--cfg=ruma_unstable_exhaustive_types` using `RUSTFLAGS` or `.cargo/config.toml` (under
/// `[build]` -> `rustflags = ["..."]`). When that setting is activated, the attribute is not
/// applied so the types are exhaustive.
///
/// # Type aliases
///
/// All kinds generate at least one type alias for the full event format. For the same example type
/// named `FooEventContent`, the first type alias generated is `type FooEvent =
/// {Kind}Event<FooEventContent>`.
///
/// The only exception for this is if the type has the `GlobalAccountData + RoomAccountData` kinds,
/// it generates two type aliases with prefixes:
///
/// * `type GlobalFooEvent = GlobalAccountDataEvent<FooEventContent>`
/// * `type RoomFooEvent = RoomAccountDataEvent<FooEventContent>`
///
/// Some kinds generate more type aliases:
///
/// * `type SyncFooEvent = Sync{Kind}Event<FooEventContent>`: an event received via the `/sync` API,
/// for the `MessageLike`, `State` and `EphemeralRoom` kinds
/// * `type OriginalFooEvent = Original{Kind}Event<FooEventContent>`, a non-redacted event, for the
/// `MessageLike` and `State` kinds
/// * `type OriginalSyncFooEvent = OriginalSync{Kind}Event<FooEventContent>`, a non-redacted event
/// received via the `/sync` API, for the `MessageLike` and `State` kinds
/// * `type RedactedFooEvent = Redacted{Kind}Event<RedactedFooEventContent>`, a redacted event, for
/// the `MessageLike` and `State` kinds
/// * `type OriginalSyncFooEvent = RedactedSync{Kind}Event<RedactedFooEventContent>`, a redacted
/// event received via the `/sync` API, for the `MessageLike` and `State` kinds
/// * `type InitialFooEvent = InitialStateEvent<FooEventContent>`, an event sent during room
/// creation, for the `State` kind
/// * `type StrippedFooEvent = StrippedStateEvent<PossiblyRedactedFooEventContent>`, an event that
/// is in a room state preview when receiving an invite, for the `State` kind
///
/// You can use `cargo doc` to find out more details, its `--document-private-items` flag also lets
/// you generate documentation for binaries or private parts of a library.
///
/// # Syntax
///
/// The basic syntax for using this macro is:
///
/// ```ignore
/// #[derive(Clone, Debug, Deserialize, Serialize, EventContent)]
/// #[ruma_event(type = "m.foo_bar", kind = MessageLike)]
/// pub struct FooBarEventContent {
/// data: String,
/// }
/// ```
///
/// ## Container attributes
///
/// The following settings can be used on the container, with the `#[ruma_event(_)]` attribute.
/// `type` and `kind` are always required.
///
/// ### `type = "m.event_type"`
///
/// The `type` of the event according to the Matrix specification, always required. This is usually
/// a string with an `m.` prefix.
///
/// Types with an account data kind can also use the `.*` suffix, if the end of the type changes
/// dynamically. It must be associated with a field that has the `#[ruma_event(type_fragment)]`
/// attribute that will store the end of the event type. Those types have the
/// `StaticEventContent::IsPrefix` type set to `True`.
///
/// ### `kind = Kind`
///
/// The kind of the event, always required. It must be one of these values, which matches the
/// [`event_enum!`] macro:
///
/// * `MessageLike` - A message-like (i.e. non-state) event sent in the timeline
/// * `State` - A state event sent in the timeline
/// * `GlobalAccountData` - Global config event
/// * `RoomAccountData` - Per-room config event
/// * `ToDevice` - Event sent directly to a device
/// * `EphemeralRoom` - Event that is not persistent in the room
///
/// It is possible to implement both account data kinds for the same type by using the syntax `kind
/// = GlobalAccountData + RoomAccountData`.
///
/// ### `alias = "m.event_type"`
///
/// An alternate `type` for the event, used during deserialization. It is usually used for
/// deserializing an event type using both its stable and unstable prefix.
///
/// ### `state_key = StringType`
///
/// The type of the state key of the event, required and only supported if the kind is `State`. This
/// type should be a string type like `String`, `EmptyStateKey` or an identifier type generated with
/// the `IdDst` macro.
///
/// ### `unsigned_type = UnsignedType`
///
/// A custom type to use for the `Unsigned` type of the `StaticStateEventContent` implementation if
/// the kind is `State`. Only necessary if the `StateUnsigned` type is not appropriate for this
/// type.
///
/// ### `custom_redacted`
///
/// If the kind requires a `Redacted{}EventContent` type and a `RedactContent` implementation and it
/// is not possible to generate them with the macro, setting this attribute prevents the macro from
/// trying to generate them. The type and trait must be implemented manually.
///
/// ### `custom_possibly_redacted`
///
/// If the kind requires a `PossiblyRedacted{}EventContent` type and it is not possible to generate
/// it with the macro, setting this attribute prevents the macro from trying to generate it. The
/// type must be implemented manually.
///
/// ### `without_relation`
///
/// If this is set, the macro will try to generate an `{}EventContentWithoutRelation` which is a
/// clone of the current type with the `relates_to` field removed.
///
/// ## Field attributes
///
/// The following settings can be used on the fields of a struct, with the `#[ruma_event(_)]`
/// attribute.
///
/// ### `skip_redaction`
///
/// If a `Redacted{}EventContent` type is generated by the macro, this field will be kept after
/// redaction.
///
/// ### `type_fragment`
///
/// If the event content's kind is account data and its type ends with the `.*`, this field is
/// required and will store the end of the event's type.
///
/// # Example
///
/// An example can be found in the docs at the root of `ruma_events`.
/// Generates trait implementations for Matrix event types.
///
/// This macro parses the name of the type on which it is applied to decide what to do, which means
/// that it only works on a fixed list of types. It also requires the type to be a struct with named
/// fields, with one of these fields named `content`.
///
/// This macro implements at least `Deserialize` for the type on which it is applied.
///
/// If the type is an `OriginalSync` or `RedactedSync` event, this implements conversion
/// helpers to the non-sync version of the event type. For example if the event type is
/// `OriginalSyncMessageLikeEvent`, this will generate `From<OriginalMessageLikeEvent> for
/// OriginalSyncMessageLikeEvent` and `OriginalSyncMessageLikeEvent::into_full_event()`.
///
/// If the type is a non-stripped timeline event, i.e. a struct with an `event_id` field, this
/// implements `PartialEq`, `Eq`, `PartialOrd` and `Ord` by comparing the `event_id` fields.
///
/// ## Field attributes
///
/// The following settings can be used on the fields of the struct, with the `#[ruma_event(_)]`
/// attribute.
///
/// ### `default`
///
/// If the field is missing, its `Default` implementation is used.
///
/// ### `default_on_error`
///
/// If an error occurs during deserialization of the value of this field, its `Default`
/// implementation is used. The error is logged with the [tracing] crate at the debug level, which
/// means that it must be a dependency of the crate where the macro is used.
///
/// ### `rename = "serialized_name"`
///
/// Use a different name when the field is serialized. The name is used both during serialization
/// and deserialization.
///
/// ### `alias = "alt_name"`
///
/// Allow a different name for the field during deserialization. This can be used several times for
/// different aliases.
///
/// You can use `cargo doc` to find out more details, its `--document-private-items` flag also lets
/// you generate documentation for binaries or private parts of a library.
///
/// [tracing]: https://crates.io/crates/tracing
/// Generates `From` implementations for an enum for all its variants.
/// Generate methods and trait impl's for DST identifier type.
///
/// This macro generates an `Owned*` wrapper type for the identifier type. This wrapper type is
/// variable, by default it'll use [`Box`], but it can be changed at compile time
/// by setting `--cfg=ruma_identifiers_storage=...` using `RUSTFLAGS` or `.cargo/config.toml` (under
/// `[build]` -> `rustflags = ["..."]`). Currently the only supported value is `Arc`, that uses
/// [`Arc`](std::sync::Arc) as a wrapper type.
///
/// This macro implements:
///
/// * Conversions to and from string types, `AsRef<[u8]>` and `AsRef<str>`, as well as `as_str()`
/// and `as_bytes()` methods. The borrowed type can be converted from a borrowed string without
/// allocation.
/// * Conversions to and from borrowed and owned type.
/// * `Deref`, `AsRef` and `Borrow` to the borrowed type for the owned type.
/// * `PartialEq` implementations for testing equality with string types and owned and borrowed
/// types.
///
/// # Attributes
///
/// * `#[ruma_api(validate = PATH)]`: the path to a function to validate the string during parsing
/// and deserialization. By default, the types implement `From` string types, when this is set
/// they implement `TryFrom`.
///
/// # Examples
///
/// ```ignore
/// # // HACK: This is "ignore" because of cyclical dependency drama.
/// use ruma_macros::IdDst;
///
/// #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, IdDst)]
/// #[ruma_id(validate = ruma_identifiers_validation::user_id::validate)]
/// pub struct UserId(str);
/// ```
/// Compile-time checked `EventId` construction.
/// Compile-time checked `RoomAliasId` construction.
/// Compile-time checked `RoomId` construction.
/// Compile-time checked `RoomVersionId` construction.
/// Compile-time checked `ServerSigningKeyVersion` construction.
/// Compile-time checked `ServerName` construction.
/// Compile-time checked `MxcUri` construction.
/// Compile-time checked `UserId` construction.
///
/// The user ID is validated using the same rules as `UserId::validate_strict()`.
/// Compile-time checked `Base64PublicKey` construction.
/// Derive the `AsRef<str>` trait for an enum.
///
/// The enum can contain unit variants, or tuple or struct variants containing a single field
/// which is a newtype struct around a type implementing `Deref` with a `Target` of `str`.
///
/// ## Example
///
/// ```
/// # use ruma_macros::AsRefStr;
/// #[derive(AsRefStr)]
/// #[ruma_enum(rename_all = "lowercase")]
/// pub enum MyEnum {
/// Unit,
/// #[ruma_enum(rename = "unstable_other_unit")]
/// OtherUnit,
/// Struct {
/// inner: PrivOwnedStr,
/// },
/// Tuple(PrivOwnedStr),
/// }
///
/// pub struct PrivOwnedStr(Box<str>);
/// ```
/// Derive the `From<T: AsRef<str> + Into<Box<str>>>` trait for an enum.
///
/// The enum can contain any number of unit variants, and must contain a single tuple or struct
/// variant containing a single field which is a newtype struct around a `Box<str>`. This tuple or
/// struct variant will be used as a fallback to catch any string that doesn't match any of the unit
/// variants.
///
/// The string to convert from must match exactly the expected string representation of a unit
/// variants to be converted to it. If there is a difference of case, it will match the fallback
/// variant instead.
/// * `#[ruma_enum(alias = "value")]` - Allow this variant to be converted from a string that is not
/// its main string representation, which is `value`. This attribute can be used several times to
/// match more strings.
///
/// _Note that for this macro, there is no difference between `rename` and `alias`. It only matters
/// when used with [`AsRefStr`]._
///
/// ## Example
///
/// ```
/// # use ruma_macros::FromString;
/// #[derive(FromString)]
/// #[ruma_enum(rename_all = "lowercase")]
/// pub enum MyEnum {
/// Unit,
/// #[ruma_enum(rename = "stable_other_unit", alias = "unstable_other_unit")]
/// OtherUnit,
/// #[doc(hidden)]
/// _Custom(PrivOwnedStr),
/// }
///
/// pub struct PrivOwnedStr(Box<str>);
/// ```
// FIXME: The following macros aren't actually interested in type details beyond name (and possibly
// generics in the future). They probably shouldn't use `DeriveInput`.
/// Derive the `as_str()` method using the `AsRef<str>` implementation of the type.
/// Derive the `fmt::Display` trait using the `AsRef<str>` implementation of the type.
/// Derive the `fmt::Debug` trait using the `AsRef<str>` implementation of the type.
/// Derive the `Serialize` trait using the `AsRef<str>` implementation of the type.
/// Derive the `Deserialize` trait using the `From<Cow<str>>` implementation of the type.
/// Derive the `Ord` and `PartialOrd` traits using the `AsRef<str>` implementation of the type.
/// Derive the `PartialEq` and `Eq` traits using the `AsRef<str>` implementation of the type.
/// Shorthand for the derives [`AsRefStr`], [`FromString`], [`DisplayAsRefStr`], [`DebugAsRefStr`],
/// [`SerializeAsRefStr`], [`DeserializeFromCowStr`], [`EqAsRefStr`] and [`OrdAsRefStr`].
///
/// The enum can contain any number of unit variants, and must contain a single tuple or struct
/// variant containing a single field which is a newtype struct around a `Box<str>`. This tuple or
/// struct variant will be used as a fallback to catch any string that doesn't match any of the unit
/// variants.
///
/// This will generate the following implementations:
///
/// * `AsRef<str>` to convert variants to their string representation, and the following
/// implementations based on it:
/// * `fn as_str(&self) -> &str`
/// * `fmt::Display`
/// * `fmt::Debug`
/// * `Serialize`
/// * `Ord` and `PartialOrd`
/// * `Eq` and `PartialEq`
/// * `From<T: AsRef<str> + Into<Box<str>>>` to convert a string to variants, and a `Deserialize`
/// implementation based on it. The string to convert from must match exactly the expected string
/// representation of a unit variants to be converted to it. If there is a difference of case, it
/// will match the fallback variant instead.
/// * `#[ruma_enum(alias = "value")]` - Allow this variant to be converted from a string that is not
/// its main string representation, which is `value`. This attribute can be used several times to
/// match more strings.
///
/// ## Example
///
/// ```ignore
/// # // HACK: This is "ignore" because of cyclical dependency drama.
/// #[derive(StringEnum)]
/// #[ruma_enum(rename_all = "lowercase")]
/// pub enum MyEnum {
/// Unit,
/// #[ruma_enum(rename = "stable_other_unit", alias = "unstable_other_unit")]
/// OtherUnit,
/// #[doc(hidden)]
/// _Custom(PrivOwnedStr),
/// }
///
/// pub struct PrivOwnedStr(Box<str>);
/// ```
/// A derive macro that generates no code, but registers the serde attribute so both `#[serde(...)]`
/// and `#[cfg_attr(..., serde(...))]` are accepted on the type, its fields and (in case the input
/// is an enum) variants fields.
/// > ⚠ If this is the only documentation you see, please navigate to the docs for
/// > `ruma_common::api::request`, where actual documentation can be found.
/// > ⚠ If this is the only documentation you see, please navigate to the docs for
/// > `ruma_common::api::response`, where actual documentation can be found.
/// Internal helper that the request macro delegates most of its work to.
/// Internal helper that the response macro delegates most of its work to.
/// A derive macro that generates no code, but registers the ruma_api attribute so both
/// `#[ruma_api(...)]` and `#[cfg_attr(..., ruma_api(...))]` are accepted on the type, its fields
/// and (in case the input is an enum) variants fields.