1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::{builder::Builder, traits::*, UnionOffset};

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

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