pub struct AssetPack { /* private fields */ }Expand description
A bundle of multiple asset files stored in a single archive.
§Format
[4 bytes magic "PACK"]
[4 bytes version = 1 as little-endian u32]
[4 bytes entry_count as little-endian u32]
For each entry:
[4 bytes path_len as little-endian u32]
[path_len bytes UTF-8 path]
[8 bytes data_offset as little-endian u64]
[8 bytes data_length as little-endian u64]
[raw concatenated asset bytes]The data section immediately follows the directory.
Implementations§
Source§impl AssetPack
impl AssetPack
Sourcepub fn from_bytes(
name: impl Into<String>,
bytes: Vec<u8>,
) -> Result<Self, String>
pub fn from_bytes( name: impl Into<String>, bytes: Vec<u8>, ) -> Result<Self, String>
Parse an asset pack from raw bytes.
Returns Err if the bytes do not match the expected format.
Sourcepub fn build(name: impl Into<String>, files: &[(&str, &[u8])]) -> Vec<u8> ⓘ
pub fn build(name: impl Into<String>, files: &[(&str, &[u8])]) -> Vec<u8> ⓘ
Build a pack from a map of virtual_path → bytes.
Sourcepub fn read(&self, virtual_path: &str) -> Option<&[u8]>
pub fn read(&self, virtual_path: &str) -> Option<&[u8]>
Read a virtual file from the pack by its path.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Number of entries in this pack.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AssetPack
impl RefUnwindSafe for AssetPack
impl Send for AssetPack
impl Sync for AssetPack
impl Unpin for AssetPack
impl UnsafeUnpin for AssetPack
impl UnwindSafe for AssetPack
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.