use std::fmt;
pub mod template;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct AssetId(#[doc(hidden)] pub u32);
impl fmt::Debug for AssetId {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "AssetId({})", self.0)
}
}
#[derive(Debug, Clone, Copy)]
pub struct Setup {
#[doc(hidden)]
pub assets: &'static [AssetDef],
#[doc(hidden)]
pub path_to_id: PathToIdMap,
#[doc(hidden)]
pub base_path: &'static str,
}
impl Setup {
#[doc(hidden)]
pub fn asset_by_path(&self, path: &str) -> Option<&AssetDef> {
self.path_to_id(path).map(|id| self.def(id))
}
#[doc(hidden)]
pub fn path_to_id(&self, path: &str) -> Option<AssetId> {
(self.path_to_id.0)(path)
}
#[doc(hidden)]
pub fn def(&self, id: AssetId) -> &AssetDef {
&self.assets[id.0 as usize]
}
}
#[derive(Clone, Copy)]
#[doc(hidden)]
pub struct PathToIdMap(pub fn(&str) -> Option<AssetId>);
impl fmt::Debug for PathToIdMap {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("<function>")
}
}
#[derive(Debug, Clone, Copy)]
#[doc(hidden)]
pub struct AssetDef {
pub path: &'static str,
pub serve: bool,
pub dynamic: bool,
pub hash: Option<(&'static str, &'static str)>,
pub template: bool,
pub append: Option<&'static [u8]>,
pub prepend: Option<&'static [u8]>,
#[cfg(any(not(debug_assertions), feature = "debug-is-prod"))]
pub content: &'static [u8],
}
impl AssetDef {
pub fn hashed_filename(&self) -> bool {
self.hash.is_some() && cfg!(any(not(debug_assertions), feature = "debug-is-prod"))
}
}