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
use crate::{builder::Builder, traits::*, Cursor, Offset, UnionOffset};
use core::mem::MaybeUninit;

impl<'a, P: Primitive, T: ?Sized + WriteAsPrimitive<P>> WriteAsPrimitive<P> for &'a T {
    #[inline]
    fn write<const N: usize>(&self, cursor: Cursor<'_, N>, buffer_position: u32) {
        T::write(*self, cursor, buffer_position)
    }
}

impl<'a, T1: ?Sized, T2: ?Sized + WriteAsOffset<T1>> WriteAsOffset<T1> for &'a T2 {
    #[inline]
    fn prepare(&self, builder: &mut Builder) -> Offset<T1> {
        T2::prepare(self, builder)
    }
}

impl<'a, P: Primitive, T: ?Sized + WriteAs<P>> WriteAs<P> for &'a T {
    type Prepared = T::Prepared;
    #[inline]
    fn prepare(&self, builder: &mut Builder) -> T::Prepared {
        T::prepare(self, builder)
    }
}

impl<'a, P: Primitive, D: ?Sized, T: ?Sized + WriteAsDefault<P, D>> WriteAsDefault<P, D> for &'a T {
    type Prepared = T::Prepared;
    #[inline]
    fn prepare(&self, builder: &mut Builder, default: &D) -> Option<T::Prepared> {
        T::prepare(self, builder, default)
    }
}

impl<'a, P: Primitive, T: ?Sized + WriteAsOptional<P>> WriteAsOptional<P> for &'a T {
    type Prepared = T::Prepared;
    #[inline]
    fn prepare(&self, builder: &mut Builder) -> Option<T::Prepared> {
        T::prepare(self, builder)
    }
}

impl<'a, T1: ?Sized, T2: ?Sized + WriteAsUnion<T1>> WriteAsUnion<T1> for &'a T2 {
    #[inline]
    fn prepare(&self, builder: &mut Builder) -> UnionOffset<T1> {
        T2::prepare(self, builder)
    }
}

impl<'a, T1: ?Sized, T2: ?Sized + WriteAsOptionalUnion<T1>> WriteAsOptionalUnion<T1> for &'a T2 {
    #[inline]
    fn prepare(&self, builder: &mut Builder) -> Option<UnionOffset<T1>> {
        T2::prepare(self, builder)
    }
}

impl<'a, P: Primitive, T: ?Sized + VectorWrite<P>> VectorWrite<P> for &'a T {
    const STRIDE: usize = T::STRIDE;
    type Value = T::Value;

    #[inline]
    fn prepare(&self, builder: &mut Builder) -> Self::Value {
        T::prepare(self, builder)
    }

    #[inline]
    unsafe fn write_values(
        values: &[Self::Value],
        bytes: *mut MaybeUninit<u8>,
        buffer_position: u32,
    ) {
        T::write_values(values, bytes, buffer_position);
    }
}