logo
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
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
/// Internal namespace.
pub( crate ) mod private
{
  use crate::exposed::*;

  // xxx : write article about the module
  // zzz : extend diagnostics_tools
  // zzz : add core::fmt to prelude

  ///
  /// Type constructor to define tuple wrapping a given type.
  ///
  /// In Rust, you often need to wrap a given type into a new one.
  /// The role of the orphan rules in particular is basically to prevent you from implementing external traits for external types.
  /// To overcome the restriction developer usually wrap the external type into a tuple introducing a new type.
  /// Type constructor does exactly that and auto-implement traits From, Into, Deref and few more for the constructed type.
  ///
  /// Besides type constructor for single element there are type constructors for `pair`, `homopair` and `many`:
  ///
  /// - `Single` to wrap single element.
  /// - `Pair` to wrap pair of distinct elements.
  /// - `HomoPair` to wrap pair of elements with the same type.
  /// - `Many` to wrap `Vec` of elements.
  ///
  /// ## Macro `types` for type constructing
  ///
  /// Macro `types` is responsible for generating code for Single, Pair, Homopair, Many. Each type constructor has its own keyword for that, but Pair and Homopair use the same keyword difference in a number of constituent types. It is possible to define all types at once.
  ///
  /// ```rust ignore
  /// {
  ///   use type_constructor::prelude::*;
  ///
  ///   types!
  ///   {
  ///
  ///     pub single MySingle : f32;
  ///     pub single SingleWithParametrized : std::sync::Arc< T : Copy >;
  ///     pub single SingleWithParameter : < T >;
  ///
  ///     pub pair MyPair : f32;
  ///     pub pair PairWithParametrized : std::sync::Arc< T1 : Copy >, std::sync::Arc< T2 : Copy >;
  ///     pub pair PairWithParameter : < T1, T2 >;
  ///
  ///     pub pair MyHomoPair : f32;
  ///     pub pair HomoPairWithParametrized : std::sync::Arc< T : Copy >;
  ///     pub pair HomoPairWithParameter : < T >;
  ///
  ///     pub many MyMany : f32;
  ///     pub many ManyWithParametrized : std::sync::Arc< T : Copy >;
  ///     pub many ManyWithParameter : < T >;
  ///
  ///   }
  /// }
  /// ```
  ///
  /// It generates more than 1000 lines of code, which otherwise you would have to write manually.
  ///
  /// ## Without macro
  ///
  /// Macro `types` is exposed to generate new types, but in some cases, it is enough to reuse already generated types of such kind. The library ships such types: Single, Pair, Homopair, Many. Note: If you avoid generating new types you will get in a position to be not able to define your own implementation of foreign traits because of orphan rule.
  ///
  /// ```rust ignore
  ///
  /// let i32_in_tuple = type_constructor::Single::< i32 >::from( 13 );
  /// dbg!( i32_in_tuple );
  /// // i32_in_tuple = Single( 13 )
  /// let i32_and_f32_in_tuple = type_constructor::Pair::< i32, f32 >::from( ( 13, 13.0 ) );
  /// dbg!( i32_and_f32_in_tuple );
  /// // vec_of_i32_in_tuple = Pair( 13, 13.0 )
  /// let two_i32_in_tuple = type_constructor::HomoPair::< i32 >::from( ( 13, 31 ) );
  /// dbg!( two_i32_in_tuple );
  /// // vec_of_i32_in_tuple = HomoPair( 13, 31 )
  /// let vec_of_i32_in_tuple = type_constructor::Many::< i32 >::from( [ 1, 2, 3 ] );
  /// dbg!( vec_of_i32_in_tuple );
  /// // vec_of_i32_in_tuple = Many([ 1, 2, 3 ])
  ///
  /// ```
  ///
  /// ## Make.
  ///
  /// Make is the variadic constructor. It's the unified interface of the arbitrary-length constructor.
  /// After implementing several traits `Make0`, `Make1` up to `MakeN` one can use make `make!` to construct instances.
  ///
  /// ```rust ignore
  /// #[ cfg( feature = "make" ) ]
  /// {
  ///   use type_constructor::prelude::*;
  ///
  ///   let instance1 : Struct1 = make!();
  ///   let instance2 : Struct1 = make!( 13 );
  ///   let instance3 : Struct1 = make!( 1, 3 );
  ///
  /// }
  /// ```
  ///
  /// ### Sample :: single-line single.
  ///
  /// To define your own single-use macro `types!`. The single-line definition looks like that.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  /// types!( pub single MySingle : i32 );
  /// let x = MySingle( 13 );
  /// println!( "x : {}", x.0 );
  /// ```
  ///
  /// It generates code:
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// pub struct MySingle( pub i32 );
  ///
  /// impl core::ops::Deref for MySingle
  /// {
  ///   type Target = i32;
  ///   fn deref( &self ) -> &Self::Target
  ///   {
  ///     &self.0
  ///   }
  /// }
  /// impl From< i32 > for MySingle
  /// {
  ///   fn from( src : i32 ) -> Self
  ///   {
  ///     Self( src )
  ///   }
  /// }
  /// impl From< MySingle > for i32
  /// {
  ///   fn from( src : MySingle ) -> Self
  ///   {
  ///     src.0
  ///   }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MySingle( 13 );
  /// println!( "x : {}", x.0 );
  /// ```
  ///
  /// ### Sample :: single with derives and attributes.
  ///
  /// It's possible to define attributes as well as derives.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  /// types!
  /// {
  ///   /// This is also attribute and macro understands it.
  ///   #[ derive( Debug ) ]
  ///   pub single MySingle : i32;
  /// }
  /// let x = MySingle( 13 );
  /// dbg!( x );
  /// ```
  ///
  /// It generates code:
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// /// This is also an attribute and macro understands it.
  /// #[ derive( Debug ) ]
  /// pub struct MySingle( pub i32 );
  ///
  /// impl core::ops::Deref for MySingle
  /// {
  ///   type Target = i32;
  ///   fn deref( &self ) -> &Self::Target
  ///   {
  ///     &self.0
  ///   }
  /// }
  /// impl From< i32 > for MySingle
  /// {
  ///   fn from( src : i32 ) -> Self
  ///   {
  ///     Self( src )
  ///   }
  /// }
  /// impl From< MySingle > for i32
  /// {
  ///   fn from( src : MySingle ) -> Self
  ///   {
  ///     src.0
  ///   }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MySingle( 13 );
  /// dbg!( x );
  /// ```
  ///
  /// ### Sample :: single with struct instead of macro.
  ///
  /// Sometimes it's sufficient to use a common type instead of defining a brand new one.
  /// You may use parameterized struct `Single< T >` instead of macro `types!` if that is the case.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  /// let x = Single::< i32 >( 13 );
  /// dbg!( x );
  /// ```
  ///
  /// ### Sample :: single with a parametrized element.
  ///
  /// Element of tuple could be parametrized.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  /// types!
  /// {
  ///   #[ derive( Debug ) ]
  ///   pub single MySingle : std::sync::Arc< T : Copy >;
  /// }
  /// let x = MySingle( std::sync::Arc::new( 13 ) );
  /// dbg!( x );
  /// ```
  ///
  /// It generates code:
  ///
  /// ```rust
  /// use type_constructor::*;
  ///
  /// #[ derive( Debug ) ]
  /// pub struct MySingle< T : Copy >( pub std::sync::Arc< T > );
  ///
  /// impl<T: Copy> core::ops::Deref for MySingle< T >
  /// {
  ///   type Target = std::sync::Arc< T >;
  ///   fn deref( &self ) -> &Self::Target
  ///   {
  ///     &self.0
  ///   }
  /// }
  /// impl< T : Copy > From< std::sync::Arc< T > > for MySingle< T >
  /// {
  ///   fn from( src : std::sync::Arc<T>) -> Self {
  ///     Self( src )
  ///   }
  /// }
  /// impl< T : Copy > From< MySingle< T > > for std::sync::Arc< T >
  /// {
  ///   fn from(src: MySingle<T>) -> Self
  ///   {
  ///     src.0
  ///   }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MySingle( std::sync::Arc::new( 13 ) );
  /// ```
  ///
  /// ### Sample :: single with parametrized tuple.
  ///
  /// Instead of parametrizing the element, it's possible to define a parametrized tuple.
  ///
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  /// types!
  /// {
  ///   #[ derive( Debug ) ]
  ///   pub single MySingle : < T : Copy >;
  /// }
  /// let x = MySingle( 13 );
  /// dbg!( x );
  /// ```
  ///
  /// It gererates code:
  ///
  /// ```rust
  /// #[ derive( Debug ) ]
  /// pub struct MySingle< T : Copy >( pub T );
  ///
  /// impl< T : Copy > core::ops::Deref
  /// for MySingle< T >
  /// {
  ///   type Target = T;
  ///   fn deref( &self ) -> &Self::Target
  ///   {
  ///     &self.0
  ///   }
  /// }
  ///
  /// impl< T : Copy > From< T >
  /// for MySingle< T >
  /// {
  ///   fn from( src : T ) -> Self
  ///   {
  ///     Self( src )
  ///   }
  /// }
  ///
  /// let x = MySingle( 13 );
  /// dbg!( 13 );
  /// ```
  ///
  /// ### Sample :: single-line pair
  ///
  /// Sometimes you need to wrap more than a single element into a tupдe. If types of elements are different use `pair`. The same macro `types` is responsible for generating code for both `single`, `pair` and also `many`.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// types!( pub pair MyPair : i32, i64 );
  /// let x = MyPair( 13, 31 );
  /// println!( "x : ( {}, {} )", x.0, x.1 );
  /// // prints : x : ( 13, 31 )
  /// ```
  ///
  /// It generates code:
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// pub struct MyPair( pub i32, pub i64 );
  ///
  /// impl From< ( i32, i64 ) > for MyPair
  /// {
  ///   fn from( src : ( i32, i64 ) ) -> Self { Self( src.0, src.1 ) }
  /// }
  ///
  /// impl From< MyPair > for ( i32, i64 )
  /// {
  ///   fn from( src : MyPair ) -> Self { ( src.0, src.1 ) }
  /// }
  ///
  /// #[cfg( feature = "make" )]
  /// impl Make2< i32, i64 > for MyPair
  /// {
  ///   fn make_2( _0 : i32, _1 : i64 ) -> Self { Self( _0, _1 ) }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MyPair( 13, 31 );
  /// println!( "x : ( {}, {} )", x.0, x.1 );
  /// ```
  ///
  /// ### Sample :: pair with parameters
  ///
  /// Just like `single` `pair` may have parameters.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// use core::fmt;
  /// types!
  /// {
  ///   #[ derive( Debug ) ]
  ///   pub pair MyPair : < T1 : fmt::Debug, T2 : fmt::Debug >;
  /// }
  /// let x = MyPair( 13, 13.0 );
  /// dbg!( x );
  /// // prints : x = MyPair( 13, 13.0 )
  /// ```
  ///
  /// It generates code:
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  /// use core::fmt;
  ///
  /// #[ derive( Debug ) ]
  /// pub struct MyPair< T1, T2 >( pub T1, pub T2 );
  ///
  /// impl< T1, T2 > From<( T1, T2 )> for MyPair< T1, T2 >
  /// {
  ///   fn from( src : ( T1, T2 ) ) -> Self { Self( src.0, src.1 ) }
  /// }
  ///
  /// impl< T1, T2 > From< MyPair< T1, T2 > > for ( T1, T2 )
  /// {
  ///   fn from( src : MyPair< T1, T2 > ) -> Self { ( src.0, src.1 ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl< T1, T2 > Make0 for MyPair< T1, T2 >
  /// where
  ///   T1 : Default,
  ///   T2 : Default,
  /// {
  ///   fn make_0() -> Self { Self( Default::default(), Default::default() ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl< T1, T2 > Make2< T1, T2 > for MyPair< T1, T2 >
  /// {
  ///   fn make_2( _0 : T1, _1 : T2 ) -> Self { Self( _0, _1 ) }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MyPair( 13, 13.0 );
  /// dbg!( x );
  /// // prints : x = MyPair( 13, 13.0 )
  /// ```
  ///
  /// ### Sample :: single-line homopair
  ///
  /// If you need to wrap pair of elements with the same type use the type constructor `pair`. The same type constructor `pair` for both `pair` and `homopair`, difference in number of types in definition, `homopair` has only one, because both its element has the same type. The same macro `types` is responsible for generating code for both `single`, `pair` and also `many`.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// types!( pub pair MyPair : i32, i64 );
  /// let x = MyPair( 13, 31 );
  /// println!( "x : ( {}, {} )", x.0, x.1 );
  /// // prints : x : ( 13, 31 )
  /// ```
  ///
  /// It gererates code:
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// pub struct MyPair( pub i32, pub i64 );
  ///
  /// impl From< ( i32, i64 ) > for MyPair
  /// {
  ///   fn from( src : ( i32, i64 ) ) -> Self { Self( src.0, src.1 ) }
  /// }
  ///
  /// impl From< MyPair > for ( i32, i64 )
  /// {
  ///   fn from( src : MyPair ) -> Self { ( src.0, src.1 ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl Make2< i32, i64 > for MyPair
  /// {
  ///   fn make_2( _0 : i32, _1 : i64 ) -> Self { Self( _0, _1 ) }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MyPair( 13, 31 );
  /// println!( "x : ( {}, {} )", x.0, x.1 );
  /// ```
  ///
  /// ### Sample :: homopair with parameters
  ///
  /// Unlike `heteropair` `homopair` has much more traits implemented for it. Among such are: `clone_as_tuple`, `clone_as_array` to clone it as either tuple or array, `as_tuple`, `as_array`, `as_slice` to reinterpret it as either tuple or array or slice, traits `From`/`Into` are implemented to convert it from/into tuple, array, slice, scalar.
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// use core::fmt;
  /// types!
  /// {
  ///   #[ derive( Debug ) ]
  ///   pub pair MyHomoPair : < T : fmt::Debug >;
  /// }
  /// let x = MyHomoPair( 13, 31 );
  /// dbg!( &x );
  /// // prints : &x = MyHomoPair( 13, 31 )
  /// let clone_as_array : [ i32 ; 2 ] = x.clone_as_array();
  /// dbg!( &clone_as_array );
  /// // prints : &clone_as_array = [ 13, 31 ]
  /// let clone_as_tuple : ( i32 , i32 ) = x.clone_as_tuple();
  /// dbg!( &clone_as_tuple );
  /// // prints : &clone_as_tuple = ( 13, 31 )
  /// ```
  ///
  /// It gererates code:
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  /// use core::fmt;
  ///
  /// #[ derive( Debug ) ]
  /// pub struct MyHomoPair< T >( pub T, pub T );
  ///
  /// impl< T > core::ops::Deref for MyHomoPair< T >
  /// {
  ///   type Target = ( T, T );
  ///
  ///   fn deref( &self ) -> &Self::Target
  ///   {
  ///     #[ cfg( debug_assertions ) ]
  ///     {
  ///       let layout1 = core::alloc::Layout::new::< Self >();
  ///       let layout2 = core::alloc::Layout::new::< Self::Target >();
  ///       debug_assert_eq!( layout1, layout2 );
  ///     }
  ///     unsafe { core::mem::transmute::< _, _ >( self ) }
  ///   }
  /// }
  ///
  /// impl< T > core::ops::DerefMut for MyHomoPair< T >
  /// {
  ///   fn deref_mut( &mut self ) -> &mut Self::Target
  ///   {
  ///     #[ cfg( debug_assertions ) ]
  ///     {
  ///       let layout1 = core::alloc::Layout::new::< Self >();
  ///       let layout2 = core::alloc::Layout::new::< Self::Target >();
  ///       debug_assert_eq!( layout1, layout2 );
  ///     }
  ///     unsafe { core::mem::transmute::< _, _ >( self ) }
  ///   }
  /// }
  ///
  /// impl< T > From< ( T, T ) > for MyHomoPair< T >
  /// {
  ///   fn from( src : ( T, T ) ) -> Self { Self( src.0, src.1 ) }
  /// }
  ///
  /// impl< T > From< MyHomoPair< T >> for ( T, T )
  /// {
  ///   fn from( src : MyHomoPair< T > ) -> Self { ( src.0, src.1 ) }
  /// }
  ///
  /// impl< T > From< [ T; 2 ] > for MyHomoPair< T >
  /// where
  ///   T : Clone,
  /// {
  ///   fn from( src : [ T; 2 ] ) -> Self { Self( src[ 0 ].clone(), src[ 1 ].clone() ) }
  /// }
  ///
  /// impl< T > From< MyHomoPair< T >> for [ T; 2 ]
  /// {
  ///   fn from( src : MyHomoPair< T > ) -> Self { [ src.0, src.1 ] }
  /// }
  ///
  /// impl< T > From< &[ T ] > for MyHomoPair< T >
  /// where
  ///   T : Clone,
  /// {
  ///   fn from( src : &[ T ] ) -> Self
  ///   {
  ///     debug_assert_eq!( src.len(), 2 );
  ///     Self( src[ 0 ].clone(), src[ 1 ].clone() )
  ///   }
  /// }
  ///
  /// impl< T > From< T > for MyHomoPair< T >
  /// where
  ///   T : Clone,
  /// {
  ///   fn from( src : T ) -> Self { Self( src.clone(), src.clone() ) }
  /// }
  ///
  /// impl< T > CloneAsTuple< ( T, T ) > for MyHomoPair< T >
  /// where
  ///   T : Clone,
  /// {
  ///   fn clone_as_tuple( &self ) -> ( T, T ) { ( self.0.clone(), self.1.clone() ) }
  /// }
  ///
  /// impl< T > CloneAsArray< T, 2 > for MyHomoPair< T >
  /// where
  ///   T : Clone,
  /// {
  ///   fn clone_as_array( &self ) -> [ T; 2 ] { [ self.0.clone(), self.1.clone() ] }
  /// }
  ///
  /// impl< T > AsTuple< ( T, T ) > for MyHomoPair< T >
  /// {
  ///   fn as_tuple( &self ) -> &( T, T ) { unsafe { core::mem::transmute::< &_, &( T, T ) >( self ) } }
  /// }
  ///
  /// impl< T > AsArray< T, 2 > for MyHomoPair< T >
  /// {
  ///   fn as_array( &self ) -> &[ T; 2 ] { unsafe { core::mem::transmute::< &_, &[ T; 2 ] >( self ) } }
  /// }
  ///
  /// impl< T > AsSlice< T > for MyHomoPair< T >
  /// {
  ///   fn as_slice( &self ) -> &[ T ] { &self.as_array()[ .. ] }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl< T > Make0 for MyHomoPair< T >
  /// where
  ///   T : Default,
  /// {
  ///   fn make_0() -> Self { Self( Default::default(), Default::default() ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl< T > Make1< T > for MyHomoPair< T >
  /// where
  ///   T : Clone,
  /// {
  ///   fn make_1( _0 : T ) -> Self { Self( _0.clone(), _0.clone() ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl< T > Make2< T, T > for MyHomoPair< T >
  /// {
  ///   fn make_2( _0 : T, _1 : T ) -> Self { Self( _0, _1 ) }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MyHomoPair( 13, 31 );
  /// dbg!( &x );
  /// // prints : &x = MyHomoPair( 13, 31 )
  /// let clone_as_array : [ i32 ; 2 ] = x.clone_as_array();
  /// dbg!( &clone_as_array );
  /// // prints : &clone_as_array = [ 13, 31 ]
  /// let clone_as_tuple : ( i32 , i32 ) = x.clone_as_tuple();
  /// dbg!( &clone_as_tuple );
  /// // prints : &clone_as_tuple = ( 13, 31 )
  /// ```
  ///
  /// ### Sample :: single-line many
  ///
  /// Use type constructor `many` to wrap `Vec` in a tuple. Similar to `single` it has essential traits implemented for it.
  ///
  /// ```rust ignore
  /// use type_constructor::prelude::*;
  ///
  /// types!( pub many MyMany : i32 );
  /// let x = MyMany::from( [ 1, 2, 3 ] );
  /// println!( "x : {:?}", x.0 );
  /// ```
  ///
  /// It generates code:
  ///
  /// ```rust
  /// use type_constructor::prelude::*;
  ///
  /// pub struct MyMany( pub std::vec::Vec< i32 > );
  ///
  /// impl core::ops::Deref for MyMany
  /// {
  ///   type Target = std::vec::Vec< i32 >;
  ///
  ///   fn deref( &self ) -> &Self::Target { &self.0 }
  /// }
  ///
  /// impl core::ops::DerefMut for MyMany
  /// {
  ///   fn deref_mut( &mut self ) -> &mut Self::Target { &mut self.0 }
  /// }
  ///
  /// impl From< i32 > for MyMany
  /// {
  ///   fn from( src : i32 ) -> Self { Self( vec![ src ] ) }
  /// }
  ///
  /// impl From< ( i32, ) > for MyMany
  /// {
  ///   fn from( src : ( i32, ) ) -> Self { Self( vec![ src.0 ] ) }
  /// }
  ///
  /// impl< const N: usize > From< [ i32; N ] > for MyMany
  /// where
  ///   i32 : Clone,
  /// {
  ///   fn from( src : [ i32; N ] ) -> Self { Self( std::vec::Vec::from( src ) ) }
  /// }
  ///
  /// impl From< &[ i32 ] > for MyMany
  /// where
  ///   i32 : Clone,
  /// {
  ///   fn from( src : &[ i32 ] ) -> Self
  ///   {
  ///     debug_assert_eq!( src.len(), 1 );
  ///     Self( std::vec::Vec::from( src ) )
  ///   }
  /// }
  ///
  /// impl AsSlice< i32 > for MyMany
  /// where
  ///   i32 : Clone,
  /// {
  ///   fn as_slice( &self ) -> &[ i32 ] { &self[ .. ] }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl Make0 for MyMany
  /// {
  ///   fn make_0() -> Self { Self( std::vec::Vec::< i32 >::new() ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl Make1< i32 > for MyMany
  /// {
  ///   fn make_1( _0 : i32 ) -> Self { Self( vec![ _0 ] ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl Make2< i32, i32 > for MyMany
  /// {
  ///   fn make_2( _0 : i32, _1 : i32 ) -> Self { Self( vec![ _0, _1 ] ) }
  /// }
  ///
  /// #[ cfg( feature = "make" ) ]
  /// impl Make3< i32, i32, i32 > for MyMany
  /// {
  ///   fn make_3( _0 : i32, _1 : i32, _2 : i32 ) -> Self { Self( vec![ _0, _1, _2 ] ) }
  /// }
  ///
  /// /* ... */
  ///
  /// let x = MyMany::from( [ 1, 2, 3 ] );
  /// println!( "x : {:?}", x.0 );
  /// ```

  // #[ doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/Readme.md" ) ) ]

  #[ macro_export ]
  macro_rules! types
  {

    // No more.

    (
    )
    =>
    {
    };

    // No more.

    (
      ;
    )
    =>
    {
    };

    // single

    (
      $( #[ $Meta : meta ] )*
      $Vis : vis
      single
      $( $Rest : tt )*
    )
    =>
    {
      $crate::_single!
      {
        $( #[ $Meta ] )*
        $Vis single
        $( $Rest )*
      }
    };

    // pair

    (
      $( #[ $Meta : meta ] )*
      $Vis : vis
      pair
      $( $Rest : tt )*
    )
    =>
    {
      $crate::_pair!
      {
        $( #[ $Meta ] )*
        $Vis pair
        $( $Rest )*
      }
    };

    // many

    (
      $( #[ $Meta : meta ] )*
      $Vis : vis
      many
      $( $Rest : tt )*
    )
    =>
    {
      $crate::_many!
      {
        $( #[ $Meta ] )*
        $Vis many
        $( $Rest )*
      }
    };

    // bad syntax

    (
      $( $Rest : tt )*
    )
    =>
    {
      compile_error!
      (
        concat!
        (
          "Bad syntax.\n",
          "Expects : {kind} {name} : {type}.\n",
          "For example : `pub single MySingle : std::sync::Arc< T : Copy >`.\n",
          "But got:\n",
          stringify!
          (
            $( $Rest )*
          ),
        )
      );
    };

  }

  pub use types;
}

/// Protected namespace of the module.
pub mod protected
{
  pub use super::orphan::*;
}

pub use protected::*;

/// Orphan namespace of the module.
pub mod orphan
{
  pub use super::exposed::*;
}

/// Exposed namespace of the module.
pub mod exposed
{
  pub use super::prelude::*;
}

pub use exposed::*;

/// Prelude to use essentials: `use my_module::prelude::*`.
pub mod prelude
{
  #[ doc( inline ) ]
  pub use super::private::
  {
    types,
  };
}