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
use crate::{builder::Builder, traits::*, Offset};
use alloc::vec::Vec;

impl<T, P> WriteAsOffset<[P]> for Vec<T>
where
    P: Primitive,
    T: VectorWrite<P>,
{
    #[inline]
    fn prepare(&self, builder: &mut Builder) -> Offset<[P]> {
        WriteAsOffset::prepare(self.as_slice(), builder)
    }
}

impl<T, P> WriteAs<Offset<[P]>> for Vec<T>
where
    P: Primitive,
    T: VectorWrite<P>,
{
    type Prepared = Offset<[P]>;

    #[inline]
    fn prepare(&self, builder: &mut Builder) -> Offset<[P]> {
        WriteAsOffset::prepare(self.as_slice(), builder)
    }
}

impl<T, P> WriteAsDefault<Offset<[P]>, ()> for Vec<T>
where
    P: Primitive,
    T: VectorWrite<P>,
{
    type Prepared = Offset<[P]>;

    #[inline]
    fn prepare(&self, builder: &mut Builder, _default: &()) -> Option<Offset<[P]>> {
        if self.is_empty() {
            None
        } else {
            Some(WriteAsOffset::prepare(self.as_slice(), builder))
        }
    }
}

impl<T, P> WriteAsOptional<Offset<[P]>> for Vec<T>
where
    P: Primitive,
    T: VectorWrite<P>,
{
    type Prepared = Offset<[P]>;

    #[inline]
    fn prepare(&self, builder: &mut Builder) -> Option<Offset<[P]>> {
        Some(WriteAsOffset::prepare(self.as_slice(), builder))
    }
}