use crate::module::ModuleIdentifier;
use crate::SizeBytes;
use meshed::prelude::*;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::fmt::{Display, Formatter};
use zerovec::ule::AsULE;
#[derive(Deserialize, Serialize, Debug, Clone, Hash, PartialOrd, PartialEq, Eq)]
#[serde(transparent)]
pub struct ChunkName<'a>(#[serde(borrow)] Cow<'a, str>);
#[derive(Deserialize, Serialize, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Copy, Clone)]
#[repr(transparent)]
pub struct ChunkId(pub u32);
impl Display for ChunkId {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
impl Identity for ChunkId {}
impl AsULE for ChunkId {
type ULE = <u32 as AsULE>::ULE;
fn to_unaligned(self) -> Self::ULE {
u32::to_unaligned(self.0)
}
fn from_unaligned(unaligned: Self::ULE) -> Self {
Self(u32::from_unaligned(unaligned))
}
}
pub struct ChunkChild;
pub struct ChunkParentOrSibling;
#[repr(transparent)]
pub struct ChunkChildren(pub Vec<ChunkId>);
pub type ChunkModules = Vec<ModuleIdentifier>;
#[derive(Debug)]
pub struct ChunkInitial(pub bool);
#[derive(Debug)]
pub struct Files(pub Vec<String>);
pub trait Chunk:
Identifiable<ChunkId>
+ Edges<ChunkId, ChunkChild>
+ Edges<ChunkId, ChunkParentOrSibling>
+ ExtractData<ChunkId>
+ ExtractData<ChunkChildren>
+ ExtractData<SizeBytes>
+ ExtractData<ChunkModules>
+ ExtractData<ChunkInitial>
+ ExtractData<Files>
+ Label<Label = ChunkId>
{
}
pub trait Chunks<T>: Query<ChunkId, T>
where
T: Chunk,
{
}