1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use crate::{ shared::utils::ArchData, utils::SlxData, NALLOC }; 
use rkyv::{ Serialize, ser::serializers::AllocSerializer, };

/// A trait helper for building a sized archive from a slx data
pub trait ArchSized {
    /// Type of the slx data
    type Archivable: SlxData + Serialize<AllocSerializer<NALLOC>>;

    /// Build the archive data from a slx data reference
    /// * Output: the archive data or an error
    fn arch_sized(&self) -> Result<ArchData<Self::Archivable>,String>;
}

impl<U> ArchSized for U where U: SlxData + Serialize<AllocSerializer<NALLOC>> {
    type Archivable = U;
    #[inline] fn arch_sized(&self) -> Result<ArchData<Self::Archivable>,String> { 
        ArchData::new_sized(self) 
    }
}