Debian Codegraph @

src/lib.rs

raw symbols SCIP
1 /*!
2 # Educe
3
4 This crate offers procedural macros designed to facilitate the swift implementation of Rust's built-in traits.
5
6 ## Features
7
8 By default, every trait this crate supports will be enabled. You can disable all of them by turning off the default features and enable only the traits that you want to use by adding them to the `features` explicitly.
9
10 For example,
11
12 ```toml
13 [dependencies.educe]
14 version = "*"
15 features = ["Debug", "Clone", "Copy", "Hash", "Default"]
16 default-features = false
17 ```
18
19 ## Traits
20
21 #### Debug
22
23 Use `#[derive(Educe)]` and `#[educe(Debug)]` to implement the `Debug` trait for a struct, enum, or union. This allows you to modify the names of your types, variants, and fields. You can also choose to ignore specific fields or set a method to replace the `Debug` trait. Additionally, you have the option to format a struct as a tuple and vice versa.
24
25 ###### Basic Usage
26
27 ```rust
28 # #[cfg(feature = "Debug")]
29 # {
30 use educe::Educe;
31
32 #[derive(Educe)]
33 #[educe(Debug)]
34 struct Struct {
35 f1: u8
36 }
37
38 #[derive(Educe)]
39 #[educe(Debug)]
40 enum Enum {
41 V1,
42 V2 {
43 f1: u8,
44 },
45 V3(u8),
46 }
47 # }
48 ```
49
50 ###### Change the Name of a Type, a Variant or a Field
51
52 The `name` parameter can rename a type, a variant or a field. If you set it to `false`, the name can be ignored or forced to show otherwise.
53
54 ```rust
55 # #[cfg(feature = "Debug")]
56 # {
57 use educe::Educe;
58
59 #[derive(Educe)]
60 #[educe(Debug(name(Struct2)))]
61 struct Struct {
62 #[educe(Debug(name(f)))]
63 f1: u8
64 }
65
66 #[derive(Educe)]
67 #[educe(Debug(name = true))]
68 enum Enum {
69 #[educe(Debug(name = false))]
70 V1,
71 #[educe(Debug(name(V)))]
72 V2 {
73 #[educe(Debug(name(f)))]
74 f1: u8,
75 },
76 #[educe(Debug(name = false))]
77 V3(u8),
78 }
79 # }
80 ```
81
82 ###### Ignore Fields
83
84 The `ignore` parameter can ignore a specific field.
85
86 ```rust
87 # #[cfg(feature = "Debug")]
88 # {
89 use educe::Educe;
90
91 #[derive(Educe)]
92 #[educe(Debug)]
93 struct Struct {
94 #[educe(Debug(ignore))]
95 f1: u8
96 }
97
98 #[derive(Educe)]
99 #[educe(Debug)]
100 enum Enum {
101 V1,
102 V2 {
103 #[educe(Debug(ignore))]
104 f1: u8,
105 },
106 V3(
107 #[educe(Debug(ignore))]
108 u8
109 ),
110 }
111 # }
112 ```
113
114 ###### Fake Structs and Tuples
115
116 With the `named_field` parameter, structs can be formatted as tuples and tuples can be formatted as structs.
117
118 ```rust
119 # #[cfg(feature = "Debug")]
120 # {
121 use educe::Educe;
122
123 #[derive(Educe)]
124 #[educe(Debug(named_field = false))]
125 struct Struct {
126 f1: u8
127 }
128
129 #[derive(Educe)]
130 #[educe(Debug)]
131 enum Enum {
132 V1,
133 #[educe(Debug(named_field = false))]
134 V2 {
135 f1: u8,
136 },
137 #[educe(Debug(named_field = true))]
138 V3(
139 u8,
140 #[educe(Debug(name(value)))]
141 i32
142 ),
143 }
144 # }
145 ```
146
147 ###### Use Another Method to Handle the Formatting
148
149 The `method` parameter can be utilized to replace the implementation of the `Debug` trait for a field, eliminating the need to implement the `Debug` trait for the type of that field.
150
151 ```rust
152 # #[cfg(feature = "Debug")]
153 # {
154 use educe::Educe;
155
156 use std::fmt::{self, Formatter};
157
158 fn fmt<T>(_s: &T, f: &mut Formatter<'_>) -> fmt::Result {
159 f.write_str("Hi")
160 }
161
162 #[derive(Educe)]
163 #[educe(Debug)]
164 enum Enum<T> {
165 V1,
166 V2 {
167 #[educe(Debug(method(fmt)))]
168 f1: u8,
169 },
170 V3(
171 #[educe(Debug(method(std::fmt::UpperHex::fmt)))]
172 u8,
173 #[educe(Debug(method(fmt)))]
174 T
175 ),
176 }
177 # }
178 ```
179
180 ###### Generic Parameters Bound to the `Debug` Trait or Others
181
182 Generic parameters will be automatically bound to the `Debug` trait if necessary.
183
184 ```rust
185 # #[cfg(feature = "Debug")]
186 # {
187 use educe::Educe;
188
189 #[derive(Educe)]
190 #[educe(Debug)]
191 enum Enum<T, K> {
192 V1,
193 V2 {
194 f1: K,
195 },
196 V3(
197 T
198 ),
199 }
200 # }
201 ```
202
203 Or you can set the where predicates by yourself.
204
205 ```rust
206 # #[cfg(feature = "Debug")]
207 # {
208 use educe::Educe;
209
210 use std::fmt::{self, Formatter};
211
212 fn fmt<D>(_s: &D, f: &mut Formatter<'_>) -> fmt::Result {
213 f.write_str("Hi")
214 }
215
216 #[derive(Educe)]
217 #[educe(Debug(bound(T: std::fmt::Debug)))]
218 enum Enum<T, K> {
219 V1,
220 V2 {
221 #[educe(Debug(method(fmt)))]
222 f1: K,
223 },
224 V3(
225 T
226 ),
227 }
228 # }
229 ```
230
231 In the above case, `T` is bound to the `Debug` trait, but `K` is not.
232
233 Or, you can have `educe` replicate the behaviour of `std`'s `derive`'s, where a bound is produced for *every* generic parameter, without regard to how it's used in the structure:
234
235 ```rust
236 # #[cfg(feature = "Debug")]
237 # {
238 use educe::Educe;
239
240 #[derive(Educe)]
241 #[educe(Debug(bound(*)))]
242 struct Struct<T> {
243 #[educe(Debug(ignore))]
244 f: T,
245 }
246 # }
247 ```
248
249 This can be useful if you don't want to make the trait implementation part of your permanent public API. In this example, `Struct<T>` doesn't implement `Debug` unless `T` does. I.e., it has a `T: Debug` bound even though that's not needed right now. Later we might want to display `f`; we wouldn't then need to make a breaking API change by adding the bound.
250
251 This was the behaviour of `Trait(bound)` in educe 0.4.x and earlier.
252
253 ###### Union
254
255 A union will be formatted as a `u8` slice because we don't know its fields at runtime. The fields of a union cannot be ignored, renamed, or formatted with other methods. The implementation is **unsafe** because it may expose uninitialized memory.
256
257 ```rust
258 # #[cfg(feature = "Debug")]
259 # {
260 use educe::Educe;
261
262 #[derive(Educe)]
263 #[educe(Debug(unsafe))]
264 union Union {
265 f1: u8,
266 f2: i32,
267 }
268 # }
269 ```
270
271 #### Clone
272
273 Use `#[derive(Educe)]` and `#[educe(Clone)]` to implement the `Clone` trait for a struct, an enum, or a union. You can set a method to replace the `Clone` trait.
274
275 ###### Basic Usage
276
277 ```rust
278 # #[cfg(feature = "Clone")]
279 # {
280 use educe::Educe;
281
282 #[derive(Educe)]
283 #[educe(Clone)]
284 struct Struct {
285 f1: u8
286 }
287
288 #[derive(Educe)]
289 #[educe(Clone)]
290 enum Enum {
291 V1,
292 V2 {
293 f1: u8,
294 },
295 V3(u8),
296 }
297 # }
298 ```
299
300 ###### Use Another Method to Perform Cloning
301
302 The `method` parameter can be utilized to replace the implementation of the `Clone` trait for a field, eliminating the need to implement the `Clone` trait for the type of that field.
303
304 ```rust
305 # #[cfg(feature = "Clone")]
306 # {
307 use educe::Educe;
308
309 fn clone(v: &u8) -> u8 {
310 v + 100
311 }
312
313 trait A {
314 fn add(&self, rhs: u8) -> Self;
315 }
316
317 fn clone2<T: A>(v: &T) -> T {
318 v.add(100)
319 }
320
321 #[derive(Educe)]
322 #[educe(Clone)]
323 enum Enum<T: A> {
324 V1,
325 V2 {
326 #[educe(Clone(method(clone)))]
327 f1: u8,
328 },
329 V3(
330 #[educe(Clone(method(clone2)))]
331 T
332 ),
333 }
334 # }
335 ```
336
337 ###### Generic Parameters Bound to the `Clone` Trait or Others
338
339 Generic parameters will be automatically bound to the `Clone` trait if necessary. If the `#[educe(Copy)]` attribute exists, they will be bound to the `Copy` trait.
340
341 ```rust
342 # #[cfg(feature = "Clone")]
343 # {
344 use educe::Educe;
345
346 #[derive(Educe)]
347 #[educe(Clone)]
348 enum Enum<T, K> {
349 V1,
350 V2 {
351 f1: K,
352 },
353 V3(
354 T
355 ),
356 }
357 # }
358 ```
359
360 Or you can set the where predicates by yourself.
361
362 ```rust
363 # #[cfg(feature = "Clone")]
364 # {
365 use educe::Educe;
366
367 trait A {
368 fn add(&self, rhs: u8) -> Self;
369 }
370
371 fn clone<T: A>(v: &T) -> T {
372 v.add(100)
373 }
374
375 #[derive(Educe)]
376 #[educe(Clone(bound(T: std::clone::Clone)))]
377 enum Enum<T, K: A> {
378 V1,
379 V2 {
380 #[educe(Clone(method(clone)))]
381 f1: K,
382 },
383 V3(
384 T
385 ),
386 }
387 # }
388 ```
389
390 In the above case, `T` is bound to the `Clone` trait, but `K` is not.
391
392 Or, you can have `educe` replicate the behaviour of `std`'s `derive`'s by using `bound(*)`. See the [`Debug`](#debug) section for more information.
393
394 ```rust
395 # #[cfg(feature = "Clone")]
396 # {
397 use educe::Educe;
398
399 trait A {
400 fn add(&self, rhs: u8) -> Self;
401 }
402
403 fn clone<T: A>(v: &T) -> T {
404 v.add(100)
405 }
406
407 #[derive(Educe)]
408 #[educe(Clone(bound(*)))]
409 struct Struct<T: A> {
410 #[educe(Clone(method(clone)))]
411 f: T,
412 }
413 # }
414 ```
415
416 ###### Union
417
418 Refer to the introduction of the `#[educe(Copy)]` attribute.
419
420 #### Copy
421
422 Use `#[derive(Educe)]` and `#[educe(Copy)]` to implement the `Copy` trait for a struct, an enum, or a union.
423
424 ###### Basic Usage
425
426 ```rust
427 # #[cfg(all(feature = "Clone", feature = "Copy"))]
428 # {
429 use educe::Educe;
430
431 #[derive(Educe)]
432 #[educe(Copy, Clone)]
433 struct Struct {
434 f1: u8
435 }
436
437 #[derive(Educe)]
438 #[educe(Copy, Clone)]
439 enum Enum {
440 V1,
441 V2 {
442 f1: u8,
443 },
444 V3(u8),
445 }
446 # }
447 ```
448
449 ###### Generic Parameters Bound to the `Copy` Trait or Others
450
451 All generic parameters will be automatically bound to the `Copy` trait.
452
453 ```rust
454 # #[cfg(all(feature = "Clone", feature = "Copy"))]
455 # {
456 use educe::Educe;
457
458 #[derive(Educe)]
459 #[educe(Copy, Clone)]
460 enum Enum<T, K> {
461 V1,
462 V2 {
463 f1: K,
464 },
465 V3(
466 T
467 ),
468 }
469 # }
470 ```
471
472 Or you can set the where predicates by yourself.
473
474 ```rust
475 # #[cfg(all(feature = "Clone", feature = "Copy"))]
476 # {
477 use educe::Educe;
478
479 trait A {
480 fn add(&self, rhs: u8) -> Self;
481 }
482
483 fn clone<T: A>(v: &T) -> T {
484 v.add(100)
485 }
486
487 #[derive(Educe)]
488 #[educe(Copy, Clone(bound(T: Copy, K: A + Copy)))]
489 enum Enum<T, K> {
490 V1,
491 V2 {
492 #[educe(Clone(method(clone)))]
493 f1: K,
494 },
495 V3(
496 T
497 ),
498 }
499 # }
500 ```
501
502 Note that utilizing custom cloning methods for a type that implements the `Copy` and `Clone` traits may not be entirely appropriate.
503
504 ###### Union
505
506 The `#[educe(Copy, Clone)]` attribute can be used for a union. The fields of a union cannot be cloned with other methods.
507
508 ```rust
509 # #[cfg(all(feature = "Clone", feature = "Copy"))]
510 # {
511 use educe::Educe;
512
513 #[derive(Educe)]
514 #[educe(Copy, Clone)]
515 union Union {
516 f1: u8,
517 }
518 # }
519 ```
520
521 #### PartialEq
522
523 Use `#[derive(Educe)]` and `#[educe(PartialEq)]` to implement the `PartialEq` trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the `PartialEq` trait.
524
525 ###### Basic Usage
526
527 ```rust
528 # #[cfg(feature = "PartialEq")]
529 # {
530 use educe::Educe;
531
532 #[derive(Educe)]
533 #[educe(PartialEq)]
534 struct Struct {
535 f1: u8
536 }
537
538 #[derive(Educe)]
539 #[educe(PartialEq)]
540 enum Enum {
541 V1,
542 V2 {
543 f1: u8,
544 },
545 V3(u8),
546 }
547 # }
548 ```
549
550 ###### Ignore Fields
551
552 The `ignore` parameter can ignore a specific field.
553
554 ```rust
555 # #[cfg(feature = "PartialEq")]
556 # {
557 use educe::Educe;
558
559 #[derive(Educe)]
560 #[educe(PartialEq)]
561 struct Struct {
562 #[educe(PartialEq(ignore))]
563 f1: u8
564 }
565
566 #[derive(Educe)]
567 #[educe(PartialEq)]
568 enum Enum {
569 V1,
570 V2 {
571 #[educe(PartialEq(ignore))]
572 f1: u8,
573 },
574 V3(
575 #[educe(PartialEq(ignore))]
576 u8
577 ),
578 }
579 # }
580 ```
581
582 ###### Use Another Method to Perform Comparison
583
584 The `method` parameter can be utilized to replace the implementation of the `PartialEq` trait for a field, eliminating the need to implement the `PartialEq` trait for the type of that field.
585
586 ```rust
587 # #[cfg(feature = "PartialEq")]
588 # {
589 use educe::Educe;
590
591 fn eq(a: &u8, b: &u8) -> bool {
592 a + 1 == *b
593 }
594
595 trait A {
596 fn is_same(&self, other: &Self) -> bool;
597 }
598
599 fn eq2<T: A>(a: &T, b: &T) -> bool {
600 a.is_same(b)
601 }
602
603 #[derive(Educe)]
604 #[educe(PartialEq)]
605 enum Enum<T: A> {
606 V1,
607 V2 {
608 #[educe(PartialEq(method(eq)))]
609 f1: u8,
610 },
611 V3(
612 #[educe(PartialEq(method(eq2)))]
613 T
614 ),
615 }
616 # }
617 ```
618
619 ###### Generic Parameters Bound to the `PartialEq` Trait or Others
620
621 Generic parameters will be automatically bound to the `PartialEq` trait if necessary.
622
623 ```rust
624 # #[cfg(feature = "PartialEq")]
625 # {
626 use educe::Educe;
627
628 #[derive(Educe)]
629 #[educe(PartialEq)]
630 enum Enum<T, K> {
631 V1,
632 V2 {
633 f1: K,
634 },
635 V3(
636 T
637 ),
638 }
639 # }
640 ```
641
642 Or you can set the where predicates by yourself.
643
644 ```rust
645 # #[cfg(feature = "PartialEq")]
646 # {
647 use educe::Educe;
648
649 trait A {
650 fn is_same(&self, other: &Self) -> bool;
651 }
652
653 fn eq<T: A>(a: &T, b: &T) -> bool {
654 a.is_same(b)
655 }
656
657 #[derive(Educe)]
658 #[educe(PartialEq(bound(T: std::cmp::PartialEq, K: A)))]
659 enum Enum<T, K> {
660 V1,
661 V2 {
662 #[educe(PartialEq(method(eq)))]
663 f1: K,
664 },
665 V3(
666 T
667 ),
668 }
669 # }
670 ```
671
672 In the above case, `T` is bound to the `PartialEq` trait, but `K` is not.
673
674 You can have `educe` replicate the behaviour of `std`'s `derive`'s by using `bound(*)`. See the [`Debug`](#debug) section for more information.
675
676 ```rust
677 # #[cfg(feature = "PartialEq")]
678 # {
679 use educe::Educe;
680
681 #[derive(Educe)]
682 #[educe(PartialEq(bound(*)))]
683 struct Struct<T> {
684 #[educe(PartialEq(ignore))]
685 f: T,
686 }
687 # }
688 ```
689
690 ###### Union
691
692 The `#[educe(PartialEq(unsafe))]` attribute can be used for a union. The fields of a union cannot be compared with other methods. The implementation is **unsafe** because it disregards the specific fields it utilizes.
693
694 ```rust
695 # #[cfg(feature = "PartialEq")]
696 # {
697 use educe::Educe;
698
699 #[derive(Educe)]
700 #[educe(PartialEq(unsafe))]
701 union Union {
702 f1: u8,
703 f2: i32
704 }
705 # }
706 ```
707
708 #### Eq
709
710 Use `#[derive(Educe)]` and `#[educe(Eq)]` to implement the `Eq` trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the `PartialEq` trait.
711
712 ###### Basic Usage
713
714 ```rust
715 # #[cfg(all(feature = "PartialEq", feature = "Eq"))]
716 # {
717 use educe::Educe;
718
719 #[derive(Educe)]
720 #[educe(PartialEq, Eq)]
721 struct Struct {
722 f1: u8
723 }
724
725 #[derive(Educe)]
726 #[educe(PartialEq, Eq)]
727 enum Enum {
728 V1,
729 V2 {
730 f1: u8,
731 },
732 V3(u8),
733 }
734 # }
735 ```
736
737 ###### Ignore Fields
738
739 The `ignore` parameter can ignore a specific field.
740
741 ```rust
742 # #[cfg(all(feature = "PartialEq", feature = "Eq"))]
743 # {
744 use educe::Educe;
745
746 #[derive(Educe)]
747 #[educe(PartialEq, Eq)]
748 struct Struct {
749 #[educe(Eq(ignore))]
750 f1: u8
751 }
752
753 #[derive(Educe)]
754 #[educe(PartialEq, Eq)]
755 enum Enum {
756 V1,
757 V2 {
758 #[educe(Eq(ignore))]
759 f1: u8,
760 },
761 V3(
762 #[educe(Eq(ignore))]
763 u8
764 ),
765 }
766 # }
767 ```
768
769 ###### Use Another Method to Perform Comparison
770
771 The `method` parameter can be utilized to replace the implementation of the `Eq` trait for a field, eliminating the need to implement the `PartialEq` trait for the type of that field.
772
773 ```rust
774 # #[cfg(all(feature = "PartialEq", feature = "Eq"))]
775 # {
776 use educe::Educe;
777
778 fn eq(a: &u8, b: &u8) -> bool {
779 a + 1 == *b
780 }
781
782 trait A {
783 fn is_same(&self, other: &Self) -> bool;
784 }
785
786 fn eq2<T: A>(a: &T, b: &T) -> bool {
787 a.is_same(b)
788 }
789
790 #[derive(Educe)]
791 #[educe(PartialEq, Eq)]
792 enum Enum<T: A> {
793 V1,
794 V2 {
795 #[educe(Eq(method(eq)))]
796 f1: u8,
797 },
798 V3(
799 #[educe(Eq(method(eq2)))]
800 T
801 ),
802 }
803 # }
804 ```
805
806 ###### Generic Parameters Bound to the `PartialEq` Trait or Others
807
808 Generic parameters will be automatically bound to the `PartialEq` trait if necessary.
809
810 ```rust
811 # #[cfg(all(feature = "PartialEq", feature = "Eq"))]
812 # {
813 use educe::Educe;
814
815 #[derive(Educe)]
816 #[educe(PartialEq, Eq)]
817 enum Enum<T, K> {
818 V1,
819 V2 {
820 f1: K,
821 },
822 V3(
823 T
824 ),
825 }
826 # }
827 ```
828
829 Or you can set the where predicates by yourself.
830
831 ```rust
832 # #[cfg(all(feature = "PartialEq", feature = "Eq"))]
833 # {
834 use educe::Educe;
835
836 trait A {
837 fn is_same(&self, other: &Self) -> bool;
838 }
839
840 fn eq<T: A>(a: &T, b: &T) -> bool {
841 a.is_same(b)
842 }
843
844 #[derive(Educe)]
845 #[educe(PartialEq(bound(T: std::cmp::PartialEq, K: A)), Eq)]
846 enum Enum<T, K> {
847 V1,
848 V2 {
849 #[educe(Eq(method(eq)))]
850 f1: K,
851 },
852 V3(
853 T
854 ),
855 }
856 # }
857 ```
858
859 ###### Union
860
861 The `#[educe(PartialEq(unsafe), Eq)]` attribute can be used for a union. The fields of a union cannot be compared with other methods. The implementation is **unsafe** because it disregards the specific fields it utilizes.
862
863 ```rust
864 # #[cfg(all(feature = "PartialEq", feature = "Eq"))]
865 # {
866 use educe::Educe;
867
868 #[derive(Educe)]
869 #[educe(PartialEq(unsafe), Eq)]
870 union Union {
871 f1: u8,
872 f2: i32
873 }
874 # }
875 ```
876
877 #### PartialOrd
878
879 Use `#[derive(Educe)]` and `#[educe(PartialOrd)]` to implement the `PartialOrd` trait for a struct or enum. You can also choose to ignore specific fields or set a method to replace the `PartialOrd` trait.
880
881 ###### Basic Usage
882
883 ```rust
884 # #[cfg(feature = "PartialOrd")]
885 # {
886 use educe::Educe;
887
888 #[derive(PartialEq, Educe)]
889 #[educe(PartialOrd)]
890 struct Struct {
891 f1: u8
892 }
893
894 #[derive(PartialEq, Educe)]
895 #[educe(PartialOrd)]
896 enum Enum {
897 V1,
898 V2 {
899 f1: u8,
900 },
901 V3(u8),
902 }
903 # }
904 ```
905
906 ###### Ignore Fields
907
908 The `ignore` parameter can ignore a specific field.
909
910 ```rust
911 # #[cfg(feature = "PartialOrd")]
912 # {
913 use educe::Educe;
914
915 #[derive(PartialEq, Educe)]
916 #[educe(PartialOrd)]
917 struct Struct {
918 #[educe(PartialOrd(ignore))]
919 f1: u8
920 }
921
922 #[derive(PartialEq, Educe)]
923 #[educe(PartialOrd)]
924 enum Enum {
925 V1,
926 V2 {
927 #[educe(PartialOrd(ignore))]
928 f1: u8,
929 },
930 V3(
931 #[educe(PartialOrd(ignore))]
932 u8
933 ),
934 }
935 # }
936 ```
937
938 ###### Use Another Method to Perform Comparison
939
940 The `method` parameter can be utilized to replace the implementation of the `PartialOrd` trait for a field, eliminating the need to implement the `PartialOrd` trait for the type of that field.
941
942 ```rust
943 # #[cfg(all(feature = "PartialEq", feature = "PartialOrd"))]
944 # {
945 use educe::Educe;
946
947 use std::cmp::Ordering;
948
949 fn partial_cmp(a: &u8, b: &u8) -> Option<Ordering> {
950 if a > b {
951 Some(Ordering::Less)
952 } else if a < b {
953 Some(Ordering::Greater)
954 } else {
955 Some(Ordering::Equal)
956 }
957 }
958
959 trait A {
960 fn value(&self) -> u8;
961 }
962
963 fn partial_cmp2<T: A>(a: &T, b: &T) -> Option<Ordering> {
964 partial_cmp(&a.value(), &b.value())
965 }
966
967 #[derive(Educe)]
968 #[educe(PartialEq, PartialOrd)]
969 enum Enum<T: A> {
970 V1,
971 V2 {
972 #[educe(PartialOrd(method(partial_cmp)))]
973 f1: u8,
974 },
975 V3(
976 #[educe(PartialOrd(method(partial_cmp2)))]
977 T
978 ),
979 }
980 # }
981 ```
982
983 ###### Ranking
984
985 Each field can add a `#[educe(PartialOrd(rank = priority_value))]` attribute, where `priority_value` is an integer value indicating its comparison precedence (lower values indicate higher priority). The default `priority_value` for a field depends on its ordinal position (lower towards the front) and starts with `isize::MIN`.
986
987 ```rust
988 # #[cfg(feature = "PartialOrd")]
989 # {
990 use educe::Educe;
991
992 #[derive(PartialEq, Educe)]
993 #[educe(PartialOrd)]
994 struct Struct {
995 #[educe(PartialOrd(rank = 1))]
996 f1: u8,
997 #[educe(PartialOrd(rank = 0))]
998 f2: u8,
999 }
1000 # }
1001 ```
1002
1003 For variants, the discriminant can be explicitly set for comparison.
1004
1005 ```rust,ignore
1006 # #[cfg(feature = "PartialOrd")]
1007 # {
1008 use educe::Educe;
1009
1010 #[derive(PartialEq, Educe)]
1011 #[educe(PartialOrd)]
1012 #[repr(u8)]
1013 enum Enum {
1014 Three { f1: u8 } = 3,
1015 Two(u8) = 2,
1016 One = 1,
1017 }
1018 # }
1019 ```
1020
1021 ###### Generic Parameters Bound to the `PartialOrd` Trait or Others
1022
1023 Generic parameters will be automatically bound to the `PartialOrd` trait if necessary.
1024
1025 ```rust
1026 # #[cfg(feature = "PartialOrd")]
1027 # {
1028 use educe::Educe;
1029
1030 #[derive(PartialEq, Educe)]
1031 #[educe(PartialOrd)]
1032 enum Enum<T, K> {
1033 V1,
1034 V2 {
1035 f1: K,
1036 },
1037 V3(
1038 T
1039 ),
1040 }
1041 # }
1042 ```
1043
1044 Or you can set the where predicates by yourself.
1045
1046 ```rust
1047 # #[cfg(feature = "PartialOrd")]
1048 # {
1049 use educe::Educe;
1050
1051 use std::cmp::Ordering;
1052
1053 trait A {
1054 fn value(&self) -> u8;
1055 }
1056
1057 fn partial_cmp<T: A>(a: &T, b: &T) -> Option<Ordering> {
1058 a.value().partial_cmp(&b.value())
1059 }
1060
1061 #[derive(PartialEq, Educe)]
1062 #[educe(PartialOrd(bound(T: std::cmp::PartialOrd, K: PartialEq + A)))]
1063 enum Enum<T, K> {
1064 V1,
1065 V2 {
1066 #[educe(PartialOrd(method(partial_cmp)))]
1067 f1: K,
1068 },
1069 V3(
1070 T
1071 ),
1072 }
1073 # }
1074 ```
1075
1076 In the above case, `T` is bound to the `PartialOrd` trait, but `K` is not.
1077
1078 You can have `educe` replicate the behaviour of `std`'s `derive`'s by using `bound(*)`. See the [`Debug`](#debug) section for more information.
1079
1080 ```rust
1081 # #[cfg(feature = "PartialOrd")]
1082 # {
1083 use educe::Educe;
1084
1085 #[derive(PartialEq, Educe)]
1086 #[educe(PartialOrd(bound(*)))]
1087 struct Struct<T> {
1088 #[educe(PartialOrd(ignore))]
1089 f: T,
1090 }
1091 # }
1092 ```
1093
1094 ###### Union
1095
1096 The `#[educe(PartialEq(unsafe))]` attribute can be used for a union. The fields of a union cannot be compared with other methods. The implementation is **unsafe** because it disregards the specific fields it utilizes.
1097
1098 ```rust
1099 # #[cfg(feature = "PartialEq")]
1100 # {
1101 use educe::Educe;
1102
1103 #[derive(Educe)]
1104 #[educe(PartialEq(unsafe))]
1105 union Union {
1106 f1: u8,
1107 f2: i32
1108 }
1109 # }
1110 ```
1111
1112 #### Ord
1113
1114 Use `#[derive(Educe)]` and `#[educe(Ord)]` to implement the `Ord` trait for a struct or enum. You can also choose to ignore specific fields or set a method to replace the `Ord` trait.
1115
1116 ###### Basic Usage
1117
1118 ```rust
1119 # #[cfg(all(feature = "PartialOrd", feature = "Ord"))]
1120 # {
1121 use educe::Educe;
1122
1123 #[derive(PartialEq, Eq, Educe)]
1124 #[educe(PartialOrd, Ord)]
1125 struct Struct {
1126 f1: u8
1127 }
1128
1129 #[derive(PartialEq, Eq, Educe)]
1130 #[educe(PartialOrd, Ord)]
1131 enum Enum {
1132 V1,
1133 V2 {
1134 f1: u8,
1135 },
1136 V3(u8),
1137 }
1138 # }
1139 ```
1140
1141 ###### Ignore Fields
1142
1143 The `ignore` parameter can ignore a specific field.
1144
1145 ```rust
1146 # #[cfg(all(feature = "PartialOrd", feature = "Ord"))]
1147 # {
1148 use educe::Educe;
1149
1150 #[derive(PartialEq, Eq, Educe)]
1151 #[educe(PartialOrd, Ord)]
1152 struct Struct {
1153 #[educe(Ord(ignore))]
1154 f1: u8
1155 }
1156
1157 #[derive(PartialEq, Eq, Educe)]
1158 #[educe(PartialOrd, Ord)]
1159 enum Enum {
1160 V1,
1161 V2 {
1162 #[educe(Ord(ignore))]
1163 f1: u8,
1164 },
1165 V3(
1166 #[educe(Ord(ignore))]
1167 u8
1168 ),
1169 }
1170 # }
1171 ```
1172
1173 ###### Use Another Method to Perform Comparison
1174
1175 The `method` parameter can be utilized to replace the implementation of the `Ord` trait for a field, eliminating the need to implement the `Ord` trait for the type of that field.
1176
1177 ```rust
1178 # #[cfg(all(feature = "PartialEq", feature = "Eq", feature = "PartialOrd", feature = "Ord"))]
1179 # {
1180 use educe::Educe;
1181
1182 use std::cmp::Ordering;
1183
1184 fn cmp(a: &u8, b: &u8) -> Ordering {
1185 if a > b {
1186 Ordering::Less
1187 } else if a < b {
1188 Ordering::Greater
1189 } else {
1190 Ordering::Equal
1191 }
1192 }
1193
1194 trait A {
1195 fn value(&self) -> u8;
1196 }
1197
1198 fn cmp2<T: A>(a: &T, b: &T) -> Ordering {
1199 cmp(&a.value(), &b.value())
1200 }
1201
1202 #[derive(Educe)]
1203 #[educe(PartialEq, Eq, PartialOrd, Ord)]
1204 enum Enum<T: A> {
1205 V1,
1206 V2 {
1207 #[educe(Ord(method(cmp)))]
1208 f1: u8,
1209 },
1210 V3(
1211 #[educe(Ord(method(cmp2)))]
1212 T
1213 ),
1214 }
1215 # }
1216 ```
1217
1218 ###### Ranking
1219
1220 Each field can add a `#[educe(Ord(rank = priority_value))]` attribute, where `priority_value` is an integer value indicating its comparison precedence (lower values indicate higher priority). The default `priority_value` for a field depends on its ordinal position (lower towards the front) and starts with `isize::MIN`.
1221
1222 ```rust
1223 # #[cfg(all(feature = "PartialOrd", feature = "Ord"))]
1224 # {
1225 use educe::Educe;
1226
1227 #[derive(PartialEq, Eq, Educe)]
1228 #[educe(PartialOrd, Ord)]
1229 struct Struct {
1230 #[educe(Ord(rank = 1))]
1231 f1: u8,
1232 #[educe(Ord(rank = 0))]
1233 f2: u8,
1234 }
1235 # }
1236 ```
1237
1238 For variants, the discriminant can be explicitly set for comparison.
1239
1240 ```rust,ignore
1241 # #[cfg(all(feature = "PartialOrd", feature = "Ord"))]
1242 # {
1243 use educe::Educe;
1244
1245 #[derive(PartialEq, Eq, Educe)]
1246 #[educe(PartialOrd, Ord)]
1247 #[repr(u8)]
1248 enum Enum {
1249 Three { f1: u8 } = 3,
1250 Two(u8) = 2,
1251 One = 1,
1252 }
1253 # }
1254 ```
1255
1256 ###### Generic Parameters Bound to the `Ord` Trait or Others
1257
1258 Generic parameters will be automatically bound to the `Ord` trait if necessary.
1259
1260 ```rust
1261 # #[cfg(all(feature = "PartialOrd", feature = "Ord"))]
1262 # {
1263 use educe::Educe;
1264
1265 #[derive(PartialEq, Eq, Educe)]
1266 #[educe(PartialOrd, Ord)]
1267 enum Enum<T, K> {
1268 V1,
1269 V2 {
1270 f1: K,
1271 },
1272 V3(
1273 T
1274 ),
1275 }
1276 # }
1277 ```
1278
1279 Or you can set the where predicates by yourself.
1280
1281 ```rust
1282 # #[cfg(all(feature = "PartialOrd", feature = "Ord"))]
1283 # {
1284 use educe::Educe;
1285
1286 use std::cmp::Ordering;
1287
1288 trait A {
1289 fn value(&self) -> u8;
1290 }
1291
1292 fn cmp<T: A>(a: &T, b: &T) -> Ordering {
1293 a.value().cmp(&b.value())
1294 }
1295
1296 #[derive(PartialEq, Eq, Educe)]
1297 #[educe(PartialOrd, Ord(bound(T: std::cmp::Ord, K: std::cmp::Ord + A)))]
1298 enum Enum<T, K> {
1299 V1,
1300 V2 {
1301 #[educe(PartialOrd(method(cmp)))]
1302 f1: K,
1303 },
1304 V3(
1305 T
1306 ),
1307 }
1308 # }
1309 ```
1310
1311 #### Hash
1312
1313 Use `#[derive(Educe)]` and `#[educe(Hash)]` to implement the `Hash` trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the `Hash` trait.
1314
1315 ###### Basic Usage
1316
1317 ```rust
1318 # #[cfg(feature = "Hash")]
1319 # {
1320 use educe::Educe;
1321
1322 #[derive(Educe)]
1323 #[educe(Hash)]
1324 struct Struct {
1325 f1: u8
1326 }
1327
1328 #[derive(Educe)]
1329 #[educe(Hash)]
1330 enum Enum {
1331 V1,
1332 V2 {
1333 f1: u8,
1334 },
1335 V3(u8),
1336 }
1337 # }
1338 ```
1339
1340 ###### Ignore Fields
1341
1342 The `ignore` parameter can ignore a specific field.
1343
1344 ```rust
1345 # #[cfg(feature = "Hash")]
1346 # {
1347 use educe::Educe;
1348
1349 #[derive(Educe)]
1350 #[educe(Hash)]
1351 struct Struct {
1352 #[educe(Hash(ignore))]
1353 f1: u8
1354 }
1355
1356 #[derive(Educe)]
1357 #[educe(Hash)]
1358 enum Enum {
1359 V1,
1360 V2 {
1361 #[educe(Hash(ignore))]
1362 f1: u8,
1363 },
1364 V3(
1365 #[educe(Hash(ignore))]
1366 u8
1367 ),
1368 }
1369 # }
1370 ```
1371
1372 ###### Use Another Method for Hashing
1373
1374 The `method` parameter can be utilized to replace the implementation of the `Hash` trait for a field, eliminating the need to implement the `Hash` trait for the type of that field.
1375
1376 ```rust
1377 # #[cfg(feature = "Hash")]
1378 # {
1379 use educe::Educe;
1380
1381 use std::hash::{Hash, Hasher};
1382
1383 fn hash<H: Hasher>(_s: &u8, state: &mut H) {
1384 Hash::hash(&100, state)
1385 }
1386
1387 fn hash2<H: Hasher, T>(_s: &T, state: &mut H) {
1388 Hash::hash(&100, state)
1389 }
1390
1391 #[derive(Educe)]
1392 #[educe(Hash)]
1393 enum Enum<T> {
1394 V1,
1395 V2 {
1396 #[educe(Hash(method(hash)))]
1397 f1: u8,
1398 },
1399 V3(
1400 #[educe(Hash(method(hash2)))]
1401 T
1402 ),
1403 }
1404 # }
1405 ```
1406
1407 ###### Generic Parameters Bound to the `Hash` Trait or Others
1408
1409 Generic parameters will be automatically bound to the `Hash` trait if necessary.
1410
1411 ```rust
1412 # #[cfg(feature = "Hash")]
1413 # {
1414 use educe::Educe;
1415
1416 #[derive(Educe)]
1417 #[educe(Hash)]
1418 enum Enum<T, K> {
1419 V1,
1420 V2 {
1421 f1: K,
1422 },
1423 V3(
1424 T
1425 ),
1426 }
1427 # }
1428 ```
1429
1430 Or you can set the where predicates by yourself.
1431
1432 ```rust
1433 # #[cfg(feature = "Hash")]
1434 # {
1435 use educe::Educe;
1436
1437 use std::hash::{Hash, Hasher};
1438
1439 trait A {
1440 fn value(&self) -> u8;
1441 }
1442
1443 fn hash<H: Hasher, T: A>(s: &T, state: &mut H) {
1444 Hash::hash(&s.value(), state)
1445 }
1446
1447 #[derive(Educe)]
1448 #[educe(Hash(bound(T: std::hash::Hash, K: A)))]
1449 enum Enum<T, K> {
1450 V1,
1451 V2 {
1452 #[educe(Hash(method(hash)))]
1453 f1: K,
1454 },
1455 V3(
1456 T
1457 ),
1458 }
1459 # }
1460 ```
1461
1462 In the above case, `T` is bound to the `Hash` trait, but `K` is not.
1463
1464 You can have `educe` replicate the behaviour of `std`'s `derive`'s by using `bound(*)`. See the [`Debug`](#debug) section for more information.
1465
1466 ```rust
1467 # #[cfg(feature = "Hash")]
1468 # {
1469 use educe::Educe;
1470
1471 #[derive(Educe)]
1472 #[educe(Hash(bound(*)))]
1473 struct Struct<T> {
1474 #[educe(Hash(ignore))]
1475 f: T,
1476 }
1477 # }
1478 ```
1479
1480 ###### Union
1481
1482 The `#[educe(PartialEq(unsafe), Eq, Hash(unsafe))]` attribute can be used for a union. The fields of a union cannot be hashed with other methods. The implementation is **unsafe** because it disregards the specific fields it utilizes.
1483
1484 ```rust
1485 # #[cfg(all(feature = "PartialEq", feature = "Eq", feature = "Hash"))]
1486 # {
1487 use educe::Educe;
1488
1489 #[derive(Educe)]
1490 #[educe(PartialEq(unsafe), Eq, Hash(unsafe))]
1491 union Union {
1492 f1: u8,
1493 f2: i32
1494 }
1495 # }
1496 ```
1497
1498 #### Default
1499
1500 Use `#[derive(Educe)]` and `#[educe(Default)]` to implement the `Default` trait for a struct, enum, or union. You can also choose to ignore specific fields or set a method to replace the `Hash` trait.
1501
1502 ###### Basic Usage
1503
1504 For enums and unions, it is necessary to designate a default variant (for enums) and a default field (for unions) unless the enum has only one variant or the union has only one field.
1505
1506 ```rust
1507 # #[cfg(feature = "Default")]
1508 # {
1509 use educe::Educe;
1510
1511 #[derive(Educe)]
1512 #[educe(Default)]
1513 struct Struct {
1514 f1: u8
1515 }
1516
1517 #[derive(Educe)]
1518 #[educe(Default)]
1519 enum Enum {
1520 V1,
1521 #[educe(Default)]
1522 V2 {
1523 f1: u8,
1524 },
1525 V3(u8),
1526 }
1527
1528 #[derive(Educe)]
1529 #[educe(Default)]
1530 union Union {
1531 f1: u8,
1532 #[educe(Default)]
1533 f2: f64,
1534 }
1535 # }
1536 ```
1537
1538 ###### The Default Value for the Entire Type
1539
1540 ```rust
1541 # #[cfg(feature = "Default")]
1542 # {
1543 use educe::Educe;
1544
1545 #[derive(Educe)]
1546 #[educe(Default(expression = Struct { f1: 1 }))]
1547 struct Struct {
1548 f1: u8
1549 }
1550
1551 #[derive(Educe)]
1552 #[educe(Default(expression = Enum::Struct { f1: 1 }))]
1553 enum Enum {
1554 Unit,
1555 Struct {
1556 f1: u8
1557 },
1558 Tuple(u8),
1559 }
1560
1561 #[derive(Educe)]
1562 #[educe(Default(expression = Union { f1: 1 }))]
1563 union Union {
1564 f1: u8,
1565 f2: f64,
1566 }
1567 # }
1568 ```
1569
1570 You may need to activate the `full` feature to enable support for advanced expressions.
1571
1572 ###### The Default Values for Specific Fields
1573
1574 ```rust
1575 # #[cfg(feature = "Default")]
1576 # {
1577 use educe::Educe;
1578
1579 #[derive(Educe)]
1580 #[educe(Default)]
1581 struct Struct {
1582 #[educe(Default = 1)]
1583 f1: u8,
1584 #[educe(Default = 11111111111111111111111111111)]
1585 f2: i128,
1586 #[educe(Default = 1.1)]
1587 f3: f64,
1588 #[educe(Default = true)]
1589 f4: bool,
1590 #[educe(Default = "Hi")]
1591 f5: &'static str,
1592 #[educe(Default = "Hello")]
1593 f6: String,
1594 #[educe(Default = 'M')]
1595 f7: char,
1596 }
1597
1598 #[derive(Educe)]
1599 #[educe(Default)]
1600 enum Enum {
1601 Unit,
1602 #[educe(Default)]
1603 Tuple(
1604 #[educe(Default(expression = 0 + 1))]
1605 u8,
1606 #[educe(Default(expression = -11111111111111111111111111111 * -1))]
1607 i128,
1608 #[educe(Default(expression = 1.0 + 0.1))]
1609 f64,
1610 #[educe(Default(expression = !false))]
1611 bool,
1612 #[educe(Default(expression = "Hi"))]
1613 &'static str,
1614 #[educe(Default(expression = String::from("Hello")))]
1615 String,
1616 #[educe(Default(expression = 'M'))]
1617 char,
1618 ),
1619 }
1620
1621 #[derive(Educe)]
1622 #[educe(Default)]
1623 union Union {
1624 f1: u8,
1625 f2: i128,
1626 f3: f64,
1627 f4: bool,
1628 #[educe(Default = "Hi")]
1629 f5: &'static str,
1630 f6: char,
1631 }
1632 # }
1633 ```
1634
1635 ###### Generic Parameters Bound to the `Default` Trait or Others
1636
1637 Generic parameters will be automatically bound to the `Default` trait if necessary.
1638
1639 ```rust
1640 # #[cfg(feature = "Default")]
1641 # {
1642 use educe::Educe;
1643
1644 #[derive(Educe)]
1645 #[educe(Default)]
1646 enum Enum<T> {
1647 Unit,
1648 #[educe(Default)]
1649 Struct {
1650 f1: T
1651 },
1652 Tuple(T),
1653 }
1654 # }
1655 ```
1656
1657 Or you can set the where predicates by yourself.
1658
1659 ```rust
1660 # #[cfg(feature = "Default")]
1661 # {
1662 use educe::Educe;
1663
1664 #[derive(Educe)]
1665 #[educe(Default(bound(T: std::default::Default)))]
1666 enum Enum<T> {
1667 Unit,
1668 #[educe(Default)]
1669 Struct {
1670 f1: T
1671 },
1672 Tuple(T),
1673 }
1674 # }
1675 ```
1676
1677 ###### The `new` Associated Function
1678
1679 With the `#[educe(Default(new))]` attribute, your type will include an additional associated function called `new`. This function can be utilized to invoke the `default` method of the `Default` trait.
1680
1681 ```rust
1682 # #[cfg(feature = "Default")]
1683 # {
1684 use educe::Educe;
1685
1686 #[derive(Educe)]
1687 #[educe(Default(new))]
1688 struct Struct {
1689 f1: u8
1690 }
1691 # }
1692 ```
1693
1694 #### Deref
1695
1696 Use `#[derive(Educe)]` and `#[educe(Deref)]` to implement the `Deref` trait for a struct or enum.
1697
1698 ###### Basic Usage
1699
1700 You must designate a field as the default for obtaining an immutable reference unless the number of fields is exactly one.
1701
1702 ```rust
1703 # #[cfg(feature = "Deref")]
1704 # {
1705 use educe::Educe;
1706
1707 #[derive(Educe)]
1708 #[educe(Deref)]
1709 struct Struct {
1710 f1: u8,
1711 #[educe(Deref)]
1712 f2: u8,
1713 }
1714
1715 #[derive(Educe)]
1716 #[educe(Deref)]
1717 enum Enum {
1718 Struct {
1719 f1: u8
1720 },
1721 Struct2 {
1722 f1: u8,
1723 #[educe(Deref)]
1724 f2: u8,
1725 },
1726 Tuple(u8),
1727 Tuple2(
1728 u8,
1729 #[educe(Deref)]
1730 u8
1731 ),
1732 }
1733 # }
1734 ```
1735
1736 #### DerefMut
1737
1738 Use `#[derive(Educe)]` and `#[educe(DerefMut)]` to implement the `DerefMut` trait for a struct or enum.
1739
1740 ###### Basic Usage
1741
1742 You must designate a field as the default for obtaining an mutable reference unless the number of fields is exactly one.
1743
1744 ```rust
1745 # #[cfg(all(feature = "Deref", feature = "DerefMut"))]
1746 # {
1747 use educe::Educe;
1748
1749 #[derive(Educe)]
1750 #[educe(Deref, DerefMut)]
1751 struct Struct {
1752 f1: u8,
1753 #[educe(Deref, DerefMut)]
1754 f2: u8,
1755 }
1756
1757 #[derive(Educe)]
1758 #[educe(Deref, DerefMut)]
1759 enum Enum {
1760 Struct {
1761 f1: u8
1762 },
1763 Struct2 {
1764 f1: u8,
1765 #[educe(Deref, DerefMut)]
1766 f2: u8,
1767 },
1768 Tuple(u8),
1769 Tuple2(
1770 #[educe(DerefMut)]
1771 u8,
1772 #[educe(Deref)]
1773 u8
1774 ),
1775 }
1776 # }
1777 ```
1778
1779 The mutable dereferencing fields do not need to be the same as the immutable dereferencing fields, but their types must be consistent.
1780
1781 #### Into
1782
1783 Use `#[derive(Educe)]` and `#[educe(Into(type))]` to implement the `Into<type>` trait for a struct or enum.
1784
1785 ###### Basic Usage
1786
1787 You need to designate a field as the default for `Into<type>` conversion unless the number of fields is exactly one. If you don't, educe will automatically try to find a proper one.
1788
1789 ```rust
1790 # #[cfg(feature = "Into")]
1791 # {
1792 use educe::Educe;
1793
1794 #[derive(Educe)]
1795 #[educe(Into(u8), Into(u16))]
1796 struct Struct {
1797 f1: u8,
1798 f2: u16,
1799 }
1800
1801 #[derive(Educe)]
1802 #[educe(Into(u8))]
1803 enum Enum {
1804 V1 {
1805 f1: u8,
1806 #[educe(Into(u8))]
1807 f2: u8,
1808 },
1809 V2 (
1810 u8
1811 ),
1812 }
1813 # }
1814 ```
1815
1816 ###### Use Another Method to Perform Into Conversion
1817
1818 The `method` parameter can be utilized to replace the implementation of the `Into` trait for a field, eliminating the need to implement the `Into` trait for the type of that field.
1819
1820 ```rust
1821 # #[cfg(feature = "Into")]
1822 # {
1823 use educe::Educe;
1824
1825 fn into(v: u16) -> u8 {
1826 v as u8
1827 }
1828
1829 #[derive(Educe)]
1830 #[educe(Into(u8))]
1831 enum Enum {
1832 V1 {
1833 #[educe(Into(u8, method(into)))]
1834 f1: u16,
1835 },
1836 V2 (
1837 u8
1838 ),
1839 }
1840 # }
1841 ```
1842
1843 ###### Generic Parameters Bound to the `Into` Trait or Others
1844
1845 Generic parameters will be automatically bound to the `Into<type>` trait if necessary.
1846
1847 ```rust
1848 # #[cfg(feature = "Into")]
1849 # {
1850 use educe::Educe;
1851
1852 #[derive(Educe)]
1853 #[educe(Into(u8))]
1854 enum Enum<T, K> {
1855 V1 {
1856 f1: K,
1857 },
1858 V2 (
1859 T
1860 ),
1861 }
1862 # }
1863 ```
1864
1865 Or you can set the where predicates by yourself.
1866
1867 ```rust
1868 # #[cfg(feature = "Into")]
1869 # {
1870 use educe::Educe;
1871
1872 fn into<T>(_v: T) -> u8 {
1873 0
1874 }
1875
1876 #[derive(Educe)]
1877 #[educe(Into(u8, bound(K: Into<u8>)))]
1878 enum Enum<T, K> {
1879 V1 {
1880 f1: K,
1881 },
1882 V2 (
1883 #[educe(Into(u8, method(into)))]
1884 T
1885 ),
1886 }
1887 # }
1888 ```
1889
1890 */
1891
1892 #![cfg_attr(docsrs, feature(doc_auto_cfg))]
1893
1894 mod commonrust-analyzer cargo educe 0.6.0 common/;
1895 #[allow(dead_code)]
1896 mod panicrust-analyzer cargo educe 0.6.0 panic/;
1897 mod supported_traitsrust-analyzer cargo educe 0.6.0 supported_traits/;
1898 mod trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/;
1899
1900 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
1901
1902 use proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#;
1903 use supported_traitsrust-analyzer cargo educe 0.6.0 supported_traits/::Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#;
1904 use synrust-analyzer cargo syn 2.0.119 crate/::{
1905 parserust-analyzer cargo syn 2.0.119 parse/::{Parserust-analyzer cargo syn 2.0.119 parse/Parse#, ParseStreamrust-analyzer cargo syn 2.0.119 parse/ParseStream#},
1906 parse_macro_inputrust-analyzer cargo syn 2.0.119 parse_macro_input/,
1907 punctuatedrust-analyzer cargo syn 2.0.119 punctuated/::Punctuatedrust-analyzer cargo syn 2.0.119 punctuated/Punctuated#,
1908 DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, Metarust-analyzer cargo syn 2.0.119 attr/Meta#, Tokenrust-analyzer cargo syn 2.0.119 token/Token!,
1909 };
1910 #[allow(unused)]
1911 use trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::{TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler#, TraitHandlerMultiplerust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandlerMultiple#};
1912
1913 fn derive_input_handlerrust-analyzer cargo educe 0.6.0 derive_input_handler().(ast: DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#> {
1914 let mut token_stream = proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#::newrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream]new().();
1915 let mut trait_meta_map: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Metarust-analyzer cargo syn 2.0.119 attr/Meta#>> = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
1916
1917 for attr in ast.attrsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#attrs..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
1918 let path = attr.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Attribute]path().();
1919
1920 if path.is_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]is_ident().("educe") {
1921 if let Metarust-analyzer cargo syn 2.0.119 attr/Meta#::Listrust-analyzer cargo syn 2.0.119 attr/Meta#List#(list) = &attr.metarust-analyzer cargo syn 2.0.119 attr/Attribute#meta. {
1922 let result =
1923 list.parse_args_withrust-analyzer cargo syn 2.0.119 attr/impl#[MetaList]parse_args_with().(Punctuatedrust-analyzer cargo syn 2.0.119 punctuated/Punctuated#::<Metarust-analyzer cargo syn 2.0.119 attr/Meta#, Tokenrust-analyzer cargo syn 2.0.119 token/Token!![,]>::parse_terminatedrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]parse_terminated().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1924
1925 for meta in result {
1926 let path = meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().();
1927
1928 let t = match Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::from_pathrust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait]from_path().(path) {
1929 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) => t,
1930 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::unsupported_traitrust-analyzer cargo educe 0.6.0 panic/unsupported_trait().(meta.pathrust-analyzer cargo syn 2.0.119 attr/impl#[Meta]path().())),
1931 };
1932
1933 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v_meta) = trait_meta_map.get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&t) {
1934 // except for those traits containing generics types
1935
1936 #[cfg(feature = "Into")]
1937 if t rust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait][`PartialEq<Self>`]eq().==rust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait][`PartialEq<Self>`]eq(). rust-analyzer cargo educe 0.6.0 supported_traits/impl#[Trait][`PartialEq<Self>`]eq().Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Intorust-analyzer cargo educe 0.6.0 supported_traits/Trait#Into# {
1938 v_meta.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(meta);
1939
1940 continue;
1941 }
1942
1943 // avoid unused warnings
1944 let _ = v_meta;
1945
1946 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::reuse_a_traitrust-analyzer cargo educe 0.6.0 panic/reuse_a_trait().(path.get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()));
1947 }
1948
1949 trait_meta_map.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(t, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![meta]);
1950 }
1951 } else {
1952 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::educe_format_incorrectrust-analyzer cargo educe 0.6.0 panic/educe_format_incorrect().(path.get_identrust-analyzer cargo syn 2.0.119 path/impl#[Path]get_ident().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().()));
1953 }
1954 }
1955 }
1956
1957 let traits: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#> = trait_meta_map.keysrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]keys().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
1958
1959 #[cfg(feature = "Debug")]
1960 {
1961 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Debugrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Debug#) {
1962 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::debugrust-analyzer cargo educe 0.6.0 trait_handlers/debug/::DebugHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/debug/DebugHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/debug/impl#[DebugHandler][TraitHandler]trait_meta_handler().(
1963 &ast,
1964 &mut token_stream,
1965 &traits,
1966 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
1967 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1968 }
1969 }
1970
1971 #[cfg(feature = "Clone")]
1972 {
1973 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Clonerust-analyzer cargo educe 0.6.0 supported_traits/Trait#Clone#) {
1974 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::clonerust-analyzer cargo educe 0.6.0 trait_handlers/clone/::CloneHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/clone/CloneHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/clone/impl#[CloneHandler][TraitHandler]trait_meta_handler().(
1975 &ast,
1976 &mut token_stream,
1977 &traits,
1978 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
1979 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1980 }
1981 }
1982
1983 #[cfg(feature = "Copy")]
1984 {
1985 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Copyrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Copy#) {
1986 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::copyrust-analyzer cargo educe 0.6.0 trait_handlers/copy/::CopyHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/copy/CopyHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/copy/impl#[CopyHandler][TraitHandler]trait_meta_handler().(
1987 &ast,
1988 &mut token_stream,
1989 &traits,
1990 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
1991 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
1992 }
1993 }
1994
1995 #[cfg(feature = "PartialEq")]
1996 {
1997 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::PartialEqrust-analyzer cargo educe 0.6.0 supported_traits/Trait#PartialEq#) {
1998 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::partial_eqrust-analyzer cargo educe 0.6.0 trait_handlers/partial_eq/::PartialEqHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/partial_eq/PartialEqHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/partial_eq/impl#[PartialEqHandler][TraitHandler]trait_meta_handler().(
1999 &ast,
2000 &mut token_stream,
2001 &traits,
2002 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2003 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2004 }
2005 }
2006
2007 #[cfg(feature = "Eq")]
2008 {
2009 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Eqrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Eq#) {
2010 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::eqrust-analyzer cargo educe 0.6.0 trait_handlers/eq/::EqHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/eq/EqHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/eq/impl#[EqHandler][TraitHandler]trait_meta_handler().(
2011 &ast,
2012 &mut token_stream,
2013 &traits,
2014 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2015 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2016 }
2017 }
2018
2019 #[cfg(feature = "PartialOrd")]
2020 {
2021 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::PartialOrdrust-analyzer cargo educe 0.6.0 supported_traits/Trait#PartialOrd#) {
2022 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::partial_ordrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/::PartialOrdHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/PartialOrdHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/partial_ord/impl#[PartialOrdHandler][TraitHandler]trait_meta_handler().(
2023 &ast,
2024 &mut token_stream,
2025 &traits,
2026 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2027 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2028 }
2029 }
2030
2031 #[cfg(feature = "Ord")]
2032 {
2033 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Ordrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Ord#) {
2034 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::ordrust-analyzer cargo educe 0.6.0 trait_handlers/ord/::OrdHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/ord/OrdHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/ord/impl#[OrdHandler][TraitHandler]trait_meta_handler().(
2035 &ast,
2036 &mut token_stream,
2037 &traits,
2038 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2039 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2040 }
2041 }
2042
2043 #[cfg(feature = "Hash")]
2044 {
2045 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Hashrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Hash#) {
2046 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::hashrust-analyzer cargo educe 0.6.0 trait_handlers/hash/::HashHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/hash/HashHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/hash/impl#[HashHandler][TraitHandler]trait_meta_handler().(
2047 &ast,
2048 &mut token_stream,
2049 &traits,
2050 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2051 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2052 }
2053 }
2054
2055 #[cfg(feature = "Default")]
2056 {
2057 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Defaultrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Default#) {
2058 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::defaultrust-analyzer cargo educe 0.6.0 trait_handlers/default/::DefaultHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/default/DefaultHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/default/impl#[DefaultHandler][TraitHandler]trait_meta_handler().(
2059 &ast,
2060 &mut token_stream,
2061 &traits,
2062 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2063 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2064 }
2065 }
2066
2067 #[cfg(feature = "Deref")]
2068 {
2069 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Derefrust-analyzer cargo educe 0.6.0 supported_traits/Trait#Deref#) {
2070 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::derefrust-analyzer cargo educe 0.6.0 trait_handlers/deref/::DerefHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref/DerefHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref/impl#[DerefHandler][TraitHandler]trait_meta_handler().(
2071 &ast,
2072 &mut token_stream,
2073 &traits,
2074 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2075 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2076 }
2077 }
2078
2079 #[cfg(feature = "DerefMut")]
2080 {
2081 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::DerefMutrust-analyzer cargo educe 0.6.0 supported_traits/Trait#DerefMut#) {
2082 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::deref_mutrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/::DerefMutHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/DerefMutHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/deref_mut/impl#[DerefMutHandler][TraitHandler]trait_meta_handler().(
2083 &ast,
2084 &mut token_stream,
2085 &traits,
2086 &meta[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
2087 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2088 }
2089 }
2090
2091 #[cfg(feature = "Into")]
2092 {
2093 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(meta) = trait_meta_map.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Intorust-analyzer cargo educe 0.6.0 supported_traits/Trait#Into#) {
2094 trait_handlersrust-analyzer cargo educe 0.6.0 trait_handlers/::intorust-analyzer cargo educe 0.6.0 trait_handlers/into/::IntoHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/into/IntoHandler#::trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/into/impl#[IntoHandler][TraitHandlerMultiple]trait_meta_handler().(
2095 &ast,
2096 &mut token_stream,
2097 &traits,
2098 meta,
2099 )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2100 }
2101 }
2102
2103 if trait_meta_map.contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::_Nothingrust-analyzer cargo educe 0.6.0 supported_traits/Trait#_Nothing#) {
2104 // avoid unused warnings
2105 let _ = &ast;
2106 let _ = &mut token_stream;
2107 let _ = traits;
2108 unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!();
2109 }
2110
2111 if token_stream.is_emptyrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream]is_empty().() {
2112 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(panicrust-analyzer cargo educe 0.6.0 panic/::derive_attribute_not_set_up_yetrust-analyzer cargo educe 0.6.0 panic/derive_attribute_not_set_up_yet().());
2113 }
2114
2115 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(token_stream)
2116 }
2117
2118 #[proc_macro_derive(Educe, attributes(educe))]
2119 pub fn educe_deriverust-analyzer cargo educe 0.6.0 Educe:(input: TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream#) -> TokenStreamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenStream# {
2120 struct MyDeriveInputrust-analyzer cargo educe 0.6.0 MyDeriveInput#(proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#);
2121
2122 impl Parserust-analyzer cargo syn 2.0.119 parse/Parse# for MyDeriveInputrust-analyzer cargo educe 0.6.0 MyDeriveInput# {
2123 #[inline]
2124 fn parserust-analyzer cargo educe 0.6.0 impl#[MyDeriveInput][Parse]parse().(input: ParseStreamrust-analyzer cargo syn 2.0.119 parse/ParseStream#) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<Selfrust-analyzer cargo educe 0.6.0 impl#[MyDeriveInput][Parse]> {
2125 let token_stream = derive_input_handlerrust-analyzer cargo educe 0.6.0 derive_input_handler().(input.parserust-analyzer cargo syn 2.0.119 parse/impl#[`ParseBuffer<'a>`]parse().::<DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
2126
2127 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo educe 0.6.0 impl#[MyDeriveInput][Parse](token_stream))
2128 }
2129 }
2130
2131 // Parse the token stream
2132 let derive_input = parse_macro_inputrust-analyzer cargo syn 2.0.119 parse_macro_input/parse_macro_input!!(input as MyDeriveInputrust-analyzer cargo educe 0.6.0 MyDeriveInput#);
2133
2134 derive_input.0rust-analyzer cargo educe 0.6.0 MyDeriveInput#0..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()
2135 }