use super::reference;
use crate::fields::Field;
use alloc::vec::Vec;
use zerovec::ZeroVec;
#[derive(Debug, PartialEq, Clone)]
pub struct Skeleton<'data>(pub(crate) ZeroVec<'data, Field>);
impl From<reference::Skeleton> for Skeleton<'_> {
fn from(input: reference::Skeleton) -> Self {
let fields = input.fields_iter().copied().collect::<Vec<_>>();
Self(ZeroVec::alloc_from_slice(&fields))
}
}
impl<'data> From<ZeroVec<'data, Field>> for Skeleton<'data> {
fn from(input: ZeroVec<'data, Field>) -> Self {
Self(input)
}
}
#[cfg(feature = "datagen")]
impl core::fmt::Display for Skeleton<'_> {
fn fmt(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
use core::fmt::Write;
for field in self.0.iter() {
let ch: char = field.symbol.into();
for _ in 0..field.length.to_len() {
formatter.write_char(ch)?;
}
}
Ok(())
}
}