use miraland_program::program_error::ProgramError;
pub trait VariableLenPack {
fn pack_into_slice(&self, dst: &mut [u8]) -> Result<(), ProgramError>;
fn unpack_from_slice(src: &[u8]) -> Result<Self, ProgramError>
where
Self: Sized;
fn get_packed_len(&self) -> Result<usize, ProgramError>;
fn pack(&self, dst: &mut [u8]) -> Result<(), ProgramError> {
if dst.len() != self.get_packed_len()? {
return Err(ProgramError::InvalidAccountData);
}
self.pack_into_slice(dst)
}
}