pub enum Assets {
Dir(PathBuf),
Pak(Arc<PakData>),
}Expand description
Unified asset source with root-relative, forward-slash paths.
Paths are normalized lexically and cannot escape the root. Directory reads also reject symlinks that resolve outside the canonical root. Hidden entries and symlinked directories are omitted from listing/packing.
Variants§
Dir(PathBuf)
Files beneath a project assets directory; read on demand.
Pak(Arc<PakData>)
Validated archive held in shared memory; no filesystem reads after opening.
Implementations§
Source§impl Assets
impl Assets
Sourcepub fn open_pak(path: &Path) -> Result<Assets>
pub fn open_pak(path: &Path) -> Result<Assets>
Reads and validates a KVASPAK1 archive.
Reports InvalidData for malformed tables, duplicate/non-canonical paths,
offsets into the table, or data ranges outside the file.
Sourcepub fn from_pak_bytes(bytes: Vec<u8>) -> Result<Assets>
pub fn from_pak_bytes(bytes: Vec<u8>) -> Result<Assets>
Opens an owned archive buffer without an intermediate disk file.
Uses the same validation as Self::open_pak.
Sourcepub fn read(&self, path: &str) -> Result<Vec<u8>>
pub fn read(&self, path: &str) -> Result<Vec<u8>>
Reads a root-relative asset into an owned byte buffer.
Errors preserve I/O kinds (NotFound, InvalidInput, etc.).
Sourcepub fn read_bytes(&self, path: &str) -> Result<Cow<'_, [u8]>>
pub fn read_bytes(&self, path: &str) -> Result<Cow<'_, [u8]>>
Reads an asset, borrowing archive bytes without copying when packed. Directory assets return an owned buffer. The borrow keeps the source alive.
Sourcepub fn read_string(&self, path: &str) -> Result<String>
pub fn read_string(&self, path: &str) -> Result<String>
Reads UTF-8 text, returning InvalidData for invalid encoding.
Sourcepub fn modified(&self, path: &str) -> Option<SystemTime>
pub fn modified(&self, path: &str) -> Option<SystemTime>
Last modification time, used for hot reload. Always None inside a pak.
Sourcepub fn list(&self) -> Vec<String>
pub fn list(&self) -> Vec<String>
All asset paths (forward slashes, relative to the root), sorted.
I/O failures return an empty list; use Self::try_list when packing/exporting.
Sourcepub fn try_list(&self) -> Result<Vec<String>>
pub fn try_list(&self) -> Result<Vec<String>>
Lists assets while preserving directory traversal errors. Hidden entries and symlinks are skipped consistently with packing.
Sourcepub fn exists(&self, path: &str) -> bool
pub fn exists(&self, path: &str) -> bool
Whether an asset is a readable file. Invalid paths and I/O errors yield false.
Sourcepub fn byte_len(&self, path: &str) -> Result<u64>
pub fn byte_len(&self, path: &str) -> Result<u64>
Asset size in bytes without reading its contents.
Sourcepub fn list_prefix(&self, prefix: &str) -> Vec<String>
pub fn list_prefix(&self, prefix: &str) -> Vec<String>
Sorted paths below a directory prefix (not a partial filename). Empty prefix lists everything; invalid prefixes return an empty list.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Assets
impl RefUnwindSafe for Assets
impl Send for Assets
impl Sync for Assets
impl Unpin for Assets
impl UnsafeUnpin for Assets
impl UnwindSafe for Assets
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSync for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.