rebound 0.4.4

Full runtime reflection for Rust, with lifetime safety
Documentation
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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
use crate::reflect::{
    Reflected, ReflectedArray, ReflectedFunction, ReflectedImpl, ReflectedPointer,
    ReflectedReference, ReflectedSlice, ReflectedTuple,
};
use crate::utils::StaticTypeMap;
use crate::value::NotOutlives;
use crate::{AssocConst, AssocFn, Field, Type};

use impl_trait_for_tuples::impl_for_tuples;
use rebound_proc::{extern_assoc_consts, extern_assoc_fns};

macro_rules! reflect_prims {
    ($($ty:ty),+ $(,)?) => {
        $(
        unsafe impl Reflected for $ty {
            type Key = $ty;

            fn name() -> String {
                stringify!($ty).into()
            }

            unsafe fn init() {
                Type::new_prim::<$ty>()
            }
        }

        unsafe impl<'a> NotOutlives<'a> for $ty {}
        )*
    };
}

// Integers
reflect_prims! {
    u8,
    u16,
    u32,
    u64,
    u128,
    usize,
    i8,
    i16,
    i32,
    i64,
    i128,
    isize,

    f32,
    f64,

    bool,
    char,
    str,
}

impl ReflectedImpl<0> for u8 {
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!(u8 @
            #[cfg(feature = "core")]
            fn from_str_radix(src: &str, radix: u32) -> Result<u8, core::num::ParseIntError>;
            const fn count_ones(self) -> u32;
            const fn count_zeros(self) -> u32;
            const fn leading_zeros(self) -> u32;
            const fn trailing_zeros(self) -> u32;
            const fn leading_ones(self) -> u32;
            const fn trailing_ones(self) -> u32;
            const fn rotate_left(self, n: u32) -> u8;
            const fn rotate_right(self, n: u32) -> u8;
            const fn swap_bytes(self) -> u8;
            const fn reverse_bits(self) -> u8;
            const fn from_be(x: u8) -> u8;
            const fn from_le(x: u8) -> u8;
            const fn to_be(self) -> u8;
            const fn to_le(self) -> u8;
            #[cfg(feature = "core")]
            const fn checked_add(self, rhs: u8) -> Option<u8>;
            // unsafe fn unchecked_add(self, rhs: u8) -> u8;
            #[cfg(feature = "core")]
            const fn checked_sub(self, rhs: u8) -> Option<u8>;
            // unsafe fn unchecked_sub(self, rhs: u8) -> u8;
            #[cfg(feature = "core")]
            const fn checked_mul(self, rhs: u8) -> Option<u8>;
            // unsafe fn unchecked_mul(self, rhs: u8) -> u8;
            #[cfg(feature = "core")]
            fn checked_div(self, rhs: u8) -> Option<u8>;
            #[cfg(feature = "core")]
            fn checked_div_euclid(self, rhs: u8) -> Option<u8>;
            #[cfg(feature = "core")]
            fn checked_rem(self, rhs: u8) -> Option<u8>;
            #[cfg(feature = "core")]
            fn checked_rem_euclid(self, rhs: u8) -> Option<u8>;
            #[cfg(feature = "core")]
            const fn checked_neg(self) -> Option<u8>;
            #[cfg(feature = "core")]
            const fn checked_shl(self, rhs: u32) -> Option<u8>;
            #[cfg(feature = "core")]
            const fn checked_shr(self, rhs: u32) -> Option<u8>;
            #[cfg(feature = "core")]
            fn checked_pow(self, exp: u32) -> Option<u8>;
            const fn saturating_add(self, rhs: u8) -> u8;
            const fn saturating_sub(self, rhs: u8) -> u8;
            const fn saturating_mul(self, rhs: u8) -> u8;
            fn saturating_pow(self, exp: u32) -> u8;
            const fn wrapping_add(self, rhs: u8) -> u8;
            const fn wrapping_sub(self, rhs: u8) -> u8;
            const fn wrapping_mul(self, rhs: u8) -> u8;
            fn wrapping_div(self, rhs: u8) -> u8;
            fn wrapping_div_euclid(self, rhs: u8) -> u8;
            fn wrapping_rem(self, rhs: u8) -> u8;
            fn wrapping_rem_euclid(self, rhs: u8) -> u8;
            const fn wrapping_neg(self) -> u8;
            const fn wrapping_shl(self, rhs: u32) -> u8;
            const fn wrapping_shr(self, rhs: u32) -> u8;
            fn wrapping_pow(self, exp: u32) -> u8;
            const fn overflowing_add(self, rhs: u8) -> (u8, bool);
            const fn overflowing_sub(self, rhs: u8) -> (u8, bool);
            const fn overflowing_mul(self, rhs: u8) -> (u8, bool);
            fn overflowing_div(self, rhs: u8) -> (u8, bool);
            fn overflowing_div_euclid(self, rhs: u8) -> (u8, bool);
            fn overflowing_rem(self, rhs: u8) -> (u8, bool);
            fn overflowing_rem_euclid(self, rhs: u8) -> (u8, bool);
            const fn overflowing_neg(self) -> (u8, bool);
            const fn overflowing_shl(self, rhs: u32) -> (u8, bool);
            const fn overflowing_shr(self, rhs: u32) -> (u8, bool);
            fn overflowing_pow(self, exp: u32) -> (u8, bool);
            fn pow(self, exp: u32) -> u8;
            fn div_euclid(self, rhs: u8) -> u8;
            fn rem_euclid(self, rhs: u8) -> u8;
            const fn is_power_of_two(self) -> bool;
            fn next_power_of_two(self) -> u8;
            #[cfg(feature = "core")]
            fn checked_next_power_of_two(self) -> Option<u8>;
            // fn wrapping_next_power_of_two(self) -> u8;
            const fn to_be_bytes(self) -> [u8; 1];
            const fn to_le_bytes(self) -> [u8; 1];
            const fn to_ne_bytes(self) -> [u8; 1];
            const fn from_be_bytes(bytes: [u8; 1]) -> u8;
            const fn from_le_bytes(bytes: [u8; 1]) -> u8;
            const fn from_ne_bytes(bytes: [u8; 1]) -> u8;
            // const fn min_value() -> u8;
            // const fn max_value() -> u8;
            const fn is_ascii(&self) -> bool;
            fn to_ascii_uppercase(&self) -> u8;
            fn to_ascii_lowercase(&self) -> u8;
            fn eq_ignore_ascii_case(&self, other: &u8) -> bool;
            fn make_ascii_uppercase(&mut self);
            fn make_ascii_lowercase(&mut self);
            const fn is_ascii_alphabetic(&self) -> bool;
            const fn is_ascii_uppercase(&self) -> bool;
            const fn is_ascii_lowercase(&self) -> bool;
            const fn is_ascii_alphanumeric(&self) -> bool;
            const fn is_ascii_digit(&self) -> bool;
            const fn is_ascii_hexdigit(&self) -> bool;
            const fn is_ascii_punctuation(&self) -> bool;
            const fn is_ascii_graphic(&self) -> bool;
            const fn is_ascii_whitespace(&self) -> bool;
            const fn is_ascii_control(&self) -> bool;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        extern_assoc_consts!(u8 @
            MIN: u8;
            MAX: u8;
            // BITS: u32;
        )
    }
}

// Floats

// Other raw types

impl ReflectedImpl<0> for bool {
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!(bool @
            // fn then_some<T>(self, t: T) -> Option<T>;
            // fn then<T, F>(self, f: F) -> Option<T>;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl ReflectedImpl<0> for char {
    fn assoc_fns() -> Vec<AssocFn> {
        #[cfg(feature = "core")]
        use core::char::{EscapeDebug, EscapeDefault, EscapeUnicode, ToLowercase, ToUppercase};

        extern_assoc_fns!(char @
            // fn from_u32(i: u32) -> Option<char>;
            // unsafe fn from_u32_unchecked(i: u32) -> char;
            // fn from_digit(num: u32, radix: u32) -> Option<char>;
            fn is_digit(self, radix: u32) -> bool;
            #[cfg(feature = "core")]
            fn to_digit(self, radix: u32) -> Option<u32>;
            #[cfg(feature = "core")]
            fn escape_unicode(self) -> EscapeUnicode;
            #[cfg(feature = "core")]
            fn escape_debug(self) -> EscapeDebug;
            #[cfg(feature = "core")]
            fn escape_default(self) -> EscapeDefault;
            fn len_utf8(self) -> usize;
            fn len_utf16(self) -> usize;
            fn encode_utf8(self, dst: &mut [u8]) -> &mut str;
            fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16];
            fn is_alphabetic(self) -> bool;
            fn is_lowercase(self) -> bool;
            fn is_uppercase(self) -> bool;
            fn is_whitespace(self) -> bool;
            fn is_alphanumeric(self) -> bool;
            fn is_control(self) -> bool;
            fn is_numeric(self) -> bool;
            #[cfg(feature = "core")]
            fn to_lowercase(self) -> ToLowercase;
            #[cfg(feature = "core")]
            fn to_uppercase(self) -> ToUppercase;
            const fn is_ascii(&self) -> bool;
            fn to_ascii_uppercase(&self) -> char;
            fn to_ascii_lowercase(&self) -> char;
            fn eq_ignore_ascii_case(&self, other: &char) -> bool;
            fn make_ascii_uppercase(&mut self);
            fn make_ascii_lowercase(&mut self);
            const fn is_ascii_alphabetic(&self) -> bool;
            const fn is_ascii_uppercase(&self) -> bool;
            const fn is_ascii_lowercase(&self) -> bool;
            const fn is_ascii_alphanumeric(&self) -> bool;
            const fn is_ascii_digit(&self) -> bool;
            const fn is_ascii_hexdigit(&self) -> bool;
            const fn is_ascii_punctuation(&self) -> bool;
            const fn is_ascii_graphic(&self) -> bool;
            const fn is_ascii_whitespace(&self) -> bool;
            const fn is_ascii_control(&self) -> bool;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        extern_assoc_consts!(char @
            // MAX: char;
            // REPLACEMENT_CHARACTER: char;
            // UNICODE_VERSION: (u8, u8, u8);
        )
    }
}

impl ReflectedImpl<0> for str {
    fn assoc_fns() -> Vec<AssocFn> {
        #[cfg(feature = "core")]
        use core::str::{
            Bytes, CharIndices, Chars, EncodeUtf16, EscapeDebug, EscapeDefault, EscapeUnicode,
            Lines, SplitAsciiWhitespace, SplitWhitespace,
        };

        extern_assoc_fns!(str @
            const fn len(&self) -> usize;
            const fn is_empty(&self) -> bool;
            fn is_char_boundary(&self, index: usize) -> bool;
            const fn as_bytes(&self) -> &[u8];
            unsafe fn as_bytes_mut(&mut self) -> &mut [u8];
            const fn as_ptr(&self) -> *const u8;
            fn as_mut_ptr(&mut self) -> *mut u8;
            fn split_at(&self, mid: usize) -> (&str, &str);
            fn split_at_mut(&mut self, mid: usize) -> (&mut str, &mut str);
            #[cfg(feature = "core")]
            fn chars(&self) -> Chars<'_>;
            #[cfg(feature = "core")]
            fn char_indices(&self) -> CharIndices<'_>;
            #[cfg(feature = "core")]
            fn bytes(&self) -> Bytes<'_>;
            #[cfg(feature = "core")]
            fn split_whitespace(&self) -> SplitWhitespace<'_>;
            #[cfg(feature = "core")]
            fn split_ascii_whitespace(&self) -> SplitAsciiWhitespace<'_>;
            #[cfg(feature = "core")]
            fn lines(&self) -> Lines<'_>;
            #[cfg(feature = "core")]
            fn encode_utf16(&self) -> EncodeUtf16<'_>;
            fn trim(&self) -> &str;
            fn trim_start(&self) -> &str;
            fn trim_end(&self) -> &str;
            fn is_ascii(&self) -> bool;
            fn eq_ignore_ascii_case(&self, other: &str) -> bool;
            fn make_ascii_uppercase(&mut self);
            fn make_ascii_lowercase(&mut self);
            #[cfg(feature = "core")]
            fn escape_debug(&self) -> EscapeDebug<'_>;
            #[cfg(feature = "core")]
            fn escape_default(&self) -> EscapeDefault<'_>;
            #[cfg(feature = "core")]
            fn escape_unicode(&self) -> EscapeUnicode<'_>;
            #[cfg(feature = "alloc")]
            fn into_boxed_bytes(self: Box<str>) -> Box<[u8]>;
            #[cfg(feature = "alloc")]
            fn to_lowercase(&self) -> String;
            #[cfg(feature = "alloc")]
            fn to_uppercase(&self) -> String;
            #[cfg(feature = "alloc")]
            fn into_string(self: Box<str>) -> String;
            #[cfg(feature = "alloc")]
            fn repeat(&self, n: usize) -> String;
            #[cfg(feature = "alloc")]
            fn to_ascii_uppercase(&self) -> String;
            #[cfg(feature = "alloc")]
            fn to_ascii_lowercase(&self) -> String;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

// Tuple reflections

unsafe impl Reflected for () {
    type Key = ();

    fn name() -> String {
        "()".into()
    }

    unsafe fn init() {
        Type::new_tuple::<()>()
    }
}

impl ReflectedTuple for () {
    fn fields() -> &'static [Field] {
        &[]
    }
}

unsafe impl<'a> NotOutlives<'a> for () {}

#[impl_for_tuples(1, 26)]
unsafe impl Reflected for Tuple {
    for_tuples!( type Key = ( #( Tuple::Key ),* ); );
    for_tuples!( where #(Tuple::Key: Sized)* );

    fn name() -> String {
        let names = [for_tuples!( #(Tuple::name()),* )];
        format!("({})", names.join(", "))
    }

    unsafe fn init() {
        Type::new_tuple::<Self>()
    }
}

#[impl_for_tuples(1, 26)]
#[tuple_types_custom_trait_bound(Reflected)]
impl ReflectedTuple for Tuple {
    for_tuples!( where #( Tuple::Key: Sized )* );

    fn fields() -> &'static [Field] {
        static TUPLE_FIELDS: StaticTypeMap<Vec<Field>> = StaticTypeMap::new();

        TUPLE_FIELDS.call_once::<Self, _>(|| {
            use crate::info::{AccessHelper, SetHelper};
            use crate::value::Value;

            let mut idx_count = 0;

            // HACK: idx_count used because the macro provides no easy way to get the current
            //       index.
            #[allow(clippy::mixed_read_write_in_expression)]
            Vec::from([for_tuples!( #( {
                let get_ptr: Option<AccessHelper> = Some(|this| {
                    // SAFETY: We know we won't borrow the item past the lifetime of the
                    //         containing value
                    let inner = unsafe { this.borrow_unsafe::<Self>() };
                    let v = Value::from_ref(&inner.Tuple);
                    // SAFETY: See rebound::ty::Ref
                    unsafe { core::mem::transmute::<Value<'_>, Value<'_>>(v) }
                });

                let set_ptr: Option<SetHelper> = Some(|this, value| {
                    // SAFETY: We know we won't borrow the item past the lifetimes off the
                    //         containing value
                    let inner = unsafe { this.borrow_unsafe_mut::<Self>() };
                    // SAFETY: The passed value is expected to be static, so we can only
                    //         cast the lifetime lower here
                    inner.Tuple = unsafe { value.cast_unsafe::<Tuple>() };
                });

                let idx = idx_count;
                idx_count += 1;

                let assoc_ty = Type::from::<Self>();
                let field_ty = Type::from::<Tuple>();

                // SAFETY: We're the privileged implementation
                unsafe { Field::new_tuple(get_ptr, set_ptr, idx, assoc_ty, field_ty) }

            } ),* )])
        })
    }
}

macro_rules! tuple_no {
    ($first:ident $first_lt:lifetime $($remaining:ident $remaining_lt:lifetime)*) => {
        unsafe impl<'no, $first_lt, $($remaining_lt,)* $first, $($remaining,)*> NotOutlives<'no> for ($first, $($remaining),*)
        where
            'no: $first_lt $(+ $remaining_lt)*,
            $first: NotOutlives<$first_lt>,
            $(
            $remaining: NotOutlives<$remaining_lt>,
            )*
        {}

        tuple_no!($($remaining $remaining_lt)*);
    };
    () => {};
}

tuple_no!(
    A 'a B 'b C 'c D 'd E 'e F 'f G 'g H 'h I 'i J 'j K 'k L 'l M 'm N 'n O 'o P 'p Q 'q R 'r S 's
    T 't U 'u V 'v W 'w X 'x Y 'y Z 'z
);

// Arrays/Slices
unsafe impl<T, const N: usize> Reflected for [T; N]
where
    T: Reflected,
    T::Key: Sized,
{
    type Key = [T::Key; N];

    fn name() -> String {
        format!("[{}; {}]", T::name(), N)
    }

    unsafe fn init() {
        Type::new_array::<[T; N]>()
    }
}

impl<T, const N: usize> ReflectedArray for [T; N]
where
    T: Reflected,
    T::Key: Sized,
{
    fn element() -> Type {
        Type::from::<T>()
    }

    fn length() -> usize {
        N
    }
}

unsafe impl<'a, T, const N: usize> NotOutlives<'a> for [T; N] where T: NotOutlives<'a> {}

unsafe impl<T> Reflected for [T]
where
    T: Reflected,
    T::Key: Sized,
{
    type Key = [T::Key];

    fn name() -> String {
        format!("[{}]", T::name())
    }

    unsafe fn init() {
        Type::new_slice::<[T]>()
    }
}

impl<T> ReflectedSlice for [T]
where
    T: Reflected,
    T::Key: Sized,
{
    fn element() -> Type {
        Type::from::<T>()
    }
}

unsafe impl<'a, 'b, T> NotOutlives<'b> for [T]
where
    'b: 'a,
    T: NotOutlives<'a>,
{
}

impl<T> ReflectedImpl<0> for [T]
where
    T: Reflected,
    T::Key: Reflected + Sized,
    <T::Key as Reflected>::Key: Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        #[cfg(feature = "core")]
        use core::ops::Range;
        #[cfg(feature = "core")]
        use core::slice::{
            Chunks, ChunksExact, ChunksExactMut, ChunksMut, Iter, IterMut, RChunks, RChunksExact,
            RChunksExactMut, RChunksMut, Windows,
        };

        extern_assoc_fns!([T] @
            const fn len(&self) -> usize;
            const fn is_empty(&self) -> bool;
            #[cfg(feature = "core")]
            fn first(&self) -> Option<&T>;
            #[cfg(feature = "core")]
            fn first_mut(&mut self) -> Option<&mut T>;
            #[cfg(feature = "core")]
            fn split_first(&self) -> Option<(&T, &[T])>;
            #[cfg(feature = "core")]
            fn split_first_mut(&mut self) -> Option<(&mut T, &mut [T])>;
            #[cfg(feature = "core")]
            fn split_last(&self) -> Option<(&T, &[T])>;
            #[cfg(feature = "core")]
            fn split_last_mut(&mut self) -> Option<(&mut T, &mut [T])>;
            #[cfg(feature = "core")]
            fn last(&self) -> Option<&T>;
            #[cfg(feature = "core")]
            fn last_mut(&mut self) -> Option<&mut T>;
            const fn as_ptr(&self) -> *const T;
            fn as_mut_ptr(&mut self) -> *mut T;
            #[cfg(feature = "core")]
            fn as_ptr_range(&self) -> Range<*const T>;
            #[cfg(feature = "core")]
            fn as_mut_ptr_range(&mut self) -> Range<*mut T>;
            fn swap(&mut self, a: usize, b: usize);
            fn reverse(&mut self);
            #[cfg(feature = "core")]
            fn iter(&self) -> Iter<'_, T>;
            #[cfg(feature = "core")]
            fn iter_mut(&mut self) -> IterMut<'_, T>;
            #[cfg(feature = "core")]
            fn windows(&self, size: usize) -> Windows<'_, T>;
            #[cfg(feature = "core")]
            fn chunks(&self, chunk_size: usize) -> Chunks<'_, T>;
            #[cfg(feature = "core")]
            fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T>;
            #[cfg(feature = "core")]
            fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T>;
            #[cfg(feature = "core")]
            fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T>;
            #[cfg(feature = "core")]
            fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T>;
            #[cfg(feature = "core")]
            fn rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, T>;
            #[cfg(feature = "core")]
            fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T>;
            #[cfg(feature = "core")]
            fn rchunks_exact_mut(&mut self, chunk_size: usize) -> RChunksExactMut<'_, T>;
            fn split_at(&self, mid: usize) -> (&[T], &[T]);
            fn split_at_mut(&mut self, mid: usize) -> (&mut [T], &mut [T]);
            fn rotate_left(&mut self, mid: usize);
            fn rotate_right(&mut self, k: usize);
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T> ReflectedImpl<1> for [T]
where
    T: Reflected + PartialEq,
    T::Key: Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([T] @
            fn contains(&self, x: &T) -> bool;
            fn starts_with(&self, needle: &[T]) -> bool;
            fn ends_with(&self, needle: &[T]) -> bool;
            // fn strip_prefix(&self, prefix: &[T]) -> Option<&[T]>;
            // fn strip_suffix(&self, suffix: &[T]) -> Option<&[T]>;
            // fn partition_dedup(&mut self) -> (&mut [T], &mut [T]);
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T> ReflectedImpl<2> for [T]
where
    T: Reflected + PartialOrd,
    T::Key: Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([T] @
            // fn is_sorted(&self) -> bool;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T> ReflectedImpl<3> for [T]
where
    T: Reflected + Ord,
    T::Key: Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([T] @
            fn sort(&mut self);
            fn sort_unstable(&mut self);
            #[cfg(feature = "core")]
            fn binary_search(&self, x: &T) -> Result<usize, usize>;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T> ReflectedImpl<4> for [T]
where
    T: Reflected + Clone,
    T::Key: Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([T] @
            // fn fill(&mut self, value: T);
            fn clone_from_slice(&mut self, src: &[T]);
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T> ReflectedImpl<5> for [T]
where
    T: Reflected + Clone + 'static,
    T::Key: Reflected + Sized,
    <T::Key as Reflected>::Key: Reflected + Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([T] @
            #[cfg(feature = "alloc")]
            fn to_vec(&self) -> Vec<T>;
            #[cfg(feature = "alloc")]
            fn into_vec(self: Box<[T]>) -> Vec<T>;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T> ReflectedImpl<6> for [T]
where
    T: Reflected + Copy,
    T::Key: Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([T] @
            fn copy_from_slice(&mut self, src: &[T]);
            fn swap_with_slice(&mut self, other: &mut [T]);
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T> ReflectedImpl<7> for [T]
where
    T: Reflected + Copy + 'static,
    T::Key: Reflected + Sized,
{
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([T] @
            #[cfg(feature = "alloc")]
            fn repeat(&self, n: usize) -> Vec<T>;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl ReflectedImpl<8> for [u8] {
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!([u8] @
            fn is_ascii(&self) -> bool;
            fn eq_ignore_ascii_case(&self, other: &[u8]) -> bool;
            fn make_ascii_uppercase(&mut self);
            fn make_ascii_lowercase(&mut self);
            #[cfg(feature = "alloc")]
            fn to_ascii_uppercase(&self) -> Vec<u8>;
            #[cfg(feature = "alloc")]
            fn to_ascii_lowercase(&self) -> Vec<u8>;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

// Pointers
unsafe impl<T: ?Sized + Reflected> Reflected for *const T {
    type Key = *const T::Key;

    fn name() -> String {
        format!("*const {}", T::name())
    }

    unsafe fn init() {
        Type::new_ptr::<*const T>();
    }
}

impl<T: ?Sized + Reflected> ReflectedPointer for *const T {
    fn element() -> Type {
        Type::from::<T>()
    }

    fn mutability() -> bool {
        false
    }
}

unsafe impl<'a, T> NotOutlives<'a> for *const T where T: NotOutlives<'a> {}

impl<T: ?Sized + Reflected> ReflectedImpl<0> for *const T {
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!(*const T @
            fn is_null(self) -> bool;
            // fn guaranteed_eq(self, other: *const T) -> bool;
            // fn guaranteed_ne(self, other: *const T) -> bool;
            // fn set_ptr_value(self, val: *const u8) -> *const T;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

impl<T: Reflected> ReflectedImpl<1> for *const T {
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!(*const T @
            unsafe fn offset_from(self, origin: *const T) -> isize;
            unsafe fn copy_to(self, dest: *mut T, count: usize);
            unsafe fn copy_to_nonoverlapping(self, dest: *mut T, count: usize);
            fn align_offset(self, align: usize) -> usize;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

// Needed because AssocFn requires static lived output. This may be fixable?
impl<T: Reflected + 'static> ReflectedImpl<2> for *const T {
    fn assoc_fns() -> Vec<AssocFn> {
        extern_assoc_fns!(*const T @
            unsafe fn offset(self, count: isize) -> *const T;
            fn wrapping_offset(self, count: isize) -> *const T;
            unsafe fn read(self) -> T;
            unsafe fn read_volatile(self) -> T;
            unsafe fn read_unaligned(self) -> T;
            unsafe fn add(self, count: usize) -> *const T;
            unsafe fn sub(self, count: usize) -> *const T;
            fn wrapping_add(self, count: usize) -> *const T;
            fn wrapping_sub(self, count: usize) -> *const T;
        )
    }

    fn assoc_consts() -> Vec<AssocConst> {
        vec![]
    }
}

unsafe impl<T: ?Sized + Reflected> Reflected for *mut T {
    type Key = *mut T::Key;

    fn name() -> String {
        format!("*mut {}", T::name())
    }

    unsafe fn init() {
        Type::new_ptr::<*mut T>();
    }
}

impl<T: ?Sized + Reflected> ReflectedPointer for *mut T {
    fn element() -> Type {
        Type::from::<T>()
    }

    fn mutability() -> bool {
        true
    }
}

unsafe impl<'a, T> NotOutlives<'a> for *mut T where T: NotOutlives<'a> {}

// References
unsafe impl<T: ?Sized + Reflected> Reflected for &T {
    type Key = &'static T::Key;

    fn name() -> String {
        format!("&{}", T::name())
    }

    unsafe fn init() {
        Type::new_ref::<&T>();
    }
}

impl<T: ?Sized + Reflected> ReflectedReference for &T {
    fn element() -> Type {
        Type::from::<T>()
    }

    fn mutability() -> bool {
        false
    }
}

unsafe impl<'a, 'b, T: ?Sized> NotOutlives<'b> for &'b T
where
    'b: 'a,
    T: NotOutlives<'a>,
{
}

unsafe impl<T: ?Sized + Reflected> Reflected for &mut T {
    type Key = &'static mut T::Key;

    fn name() -> String {
        format!("&mut {}", T::name())
    }

    unsafe fn init() {
        Type::new_ref::<&mut T>();
    }
}

impl<T: ?Sized + Reflected> ReflectedReference for &mut T {
    fn element() -> Type {
        Type::from::<T>()
    }

    fn mutability() -> bool {
        true
    }
}

unsafe impl<'a, 'b, T: ?Sized> NotOutlives<'b> for &'b mut T
where
    'b: 'a,
    T: NotOutlives<'a>,
{
}

// Function pointers
unsafe impl<T: Reflected> Reflected for fn() -> T {
    type Key = fn() -> T::Key;

    fn name() -> String {
        format!("fn() -> {}", T::name())
    }

    unsafe fn init() {
        Type::new_fn::<fn() -> T>()
    }
}

impl<T: Reflected> ReflectedFunction for fn() -> T {
    fn args() -> Vec<Type> {
        vec![]
    }

    fn ret() -> Type {
        Type::from::<T>()
    }
}

unsafe impl<T: Reflected, A0: Reflected> Reflected for fn(A0) -> T {
    type Key = fn(A0::Key) -> T::Key;

    fn name() -> String {
        format!("fn({}) -> {}", A0::name(), T::name())
    }

    unsafe fn init() {
        Type::new_fn::<fn(A0) -> T>()
    }
}

impl<T: Reflected, A0: Reflected> ReflectedFunction for fn(A0) -> T {
    fn args() -> Vec<Type> {
        vec![Type::from::<A0>()]
    }

    fn ret() -> Type {
        Type::from::<T>()
    }
}

unsafe impl<T: Reflected, A0: Reflected, A1: Reflected> Reflected for fn(A0, A1) -> T {
    type Key = fn(A0::Key, A1::Key) -> T::Key;

    fn name() -> String {
        format!("fn({}, {}) -> {}", A0::name(), A1::name(), T::name())
    }

    unsafe fn init() {
        Type::new_fn::<fn(A0, A1) -> T>()
    }
}

impl<T: Reflected, A0: Reflected, A1: Reflected> ReflectedFunction for fn(A0, A1) -> T {
    fn args() -> Vec<Type> {
        vec![Type::from::<A0>(), Type::from::<A1>()]
    }

    fn ret() -> Type {
        Type::from::<T>()
    }
}

unsafe impl<T: Reflected, A0: Reflected, A1: Reflected, A2: Reflected> Reflected
    for fn(A0, A1, A2) -> T
{
    type Key = fn(A0::Key, A1::Key, A2::Key) -> T::Key;

    fn name() -> String {
        format!(
            "fn({}, {}, {}) -> {}",
            A0::name(),
            A1::name(),
            A2::name(),
            T::name()
        )
    }

    unsafe fn init() {
        Type::new_fn::<fn(A0, A1, A2) -> T>()
    }
}

impl<T: Reflected, A0: Reflected, A1: Reflected, A2: Reflected> ReflectedFunction
    for fn(A0, A1, A2) -> T
{
    fn args() -> Vec<Type> {
        vec![Type::from::<A0>(), Type::from::<A1>(), Type::from::<A2>()]
    }

    fn ret() -> Type {
        Type::from::<T>()
    }
}

// Never type
#[cfg(feature = "never-type")]
unsafe impl Reflected for ! {
    type Key = !;

    fn name() -> String {
        "!".into()
    }

    unsafe fn init() {
        Type::new_prim::<!>()
    }
}