Struct Bundle
pub struct Bundle { /* private fields */ }Implementations§
§impl Bundle
impl Bundle
pub fn insert(&mut self, path: &str, bytes: &[u8]) -> Result<(), AssetError>
pub fn insert(&mut self, path: &str, bytes: &[u8]) -> Result<(), AssetError>
Insert or replace content at a canonical path. Identical content keeps the existing payload Arc without allocating a replacement.
use ferravex_engine::assets::Bundle;
let mut bundle = Bundle::default();
bundle.insert("meta/version", b"v1")?;
let reader = bundle.get("meta/version").unwrap();
bundle.insert("meta/version", b"v1")?;
assert!(std::sync::Arc::ptr_eq(&reader, &bundle.get("meta/version").unwrap()));pub fn is_empty(&self) -> bool
pub fn decoded_bytes(&self) -> usize
pub fn decoded_bytes(&self) -> usize
Total decoded payload bytes, excluding names and externally retained readers.
pub fn remove(&mut self, path: &str) -> Option<Arc<[u8]>>
pub fn remove(&mut self, path: &str) -> Option<Arc<[u8]>>
Remove an asset. Existing Arc readers remain valid.
pub fn apply_edits<'a>(
&mut self,
edits: impl IntoIterator<Item = (&'a str, Option<&'a [u8]>)>,
) -> Result<(), AssetError>
pub fn apply_edits<'a>( &mut self, edits: impl IntoIterator<Item = (&'a str, Option<&'a [u8]>)>, ) -> Result<(), AssetError>
Apply puts (Some(bytes)) and removals (None) in order, committing only
if every path and intermediate capacity is valid. Payloads are Arc-shared.
Assets with unchanged final content retain their original payload Arcs,
including removal/reinsertion or edits reverted within this transaction.
pub fn apply_edits_checked<'a>(
&mut self,
edits: impl IntoIterator<Item = (&'a str, Option<&'a [u8]>)>,
) -> Result<(), AssetEditError>
pub fn apply_edits_checked<'a>( &mut self, edits: impl IntoIterator<Item = (&'a str, Option<&'a [u8]>)>, ) -> Result<(), AssetEditError>
Apply a transaction using normalize_path, reporting the first failing
edit’s index, original path and cause. Limits apply after each edit, just
as with Self::apply_edits. Aliases of a path are applied in input order;
removing an absent asset is a successful no-op.
Assets with unchanged final content retain their original payload Arcs.
use ferravex_engine::assets::Bundle;
let mut bundle = Bundle::default();
bundle.apply_edits_checked([(r".\meta\version", Some(&b"v1"[..]))])?;
let before = bundle.encode();
let error = bundle.apply_edits_checked([
("meta/version", None), ("../escape", None),
]).unwrap_err();
assert_eq!(error.index, 1);
assert_eq!(bundle.encode(), before);pub fn subtree(&self, directory: &str) -> Result<Bundle, AssetError>
pub fn subtree(&self, directory: &str) -> Result<Bundle, AssetError>
Copy a directory’s contents with the directory prefix stripped. Empty prefix selects the complete bundle. Payload allocations are shared.
pub fn diff(&self, next: &Bundle) -> BundleDiff
pub fn diff(&self, next: &Bundle) -> BundleDiff
Compare decoded content, ignoring Arc identity and encoding choices.
pub fn get(&self, path: &str) -> Option<Arc<[u8]>>
pub fn get_checked(&self, path: &str) -> Result<Arc<[u8]>, AssetLookupError>
pub fn get_checked(&self, path: &str) -> Result<Arc<[u8]>, AssetLookupError>
Retrieve shared bytes using a normalized authoring path. Distinguishes invalid paths from missing assets. The reader survives edits and reloads. Successful canonical lookups allocate no memory and copy no payloads.
use ferravex_engine::assets::{AssetLookupError, Bundle};
let mut bundle = Bundle::default();
bundle.insert("meta/version", b"v1")?;
let reader = bundle.get_checked(r".\meta\version")?;
bundle.remove("meta/version");
assert_eq!(&*reader, b"v1");
assert!(matches!(bundle.get_checked("meta/version"),
Err(AssetLookupError::Missing { .. })));pub fn get_text(&self, path: &str) -> Result<&str, AssetLookupError>
pub fn get_text(&self, path: &str) -> Result<&str, AssetLookupError>
Borrow validated UTF-8 text. Invalid text reports its canonical path and
std::str::Utf8Error, including the first invalid byte’s offset.
use ferravex_engine::assets::Bundle;
let mut bundle = Bundle::default();
bundle.insert("dialogue/greeting", "Hello, 世界!".as_bytes())?;
assert_eq!(bundle.get_text("./dialogue//greeting")?, "Hello, 世界!");pub fn get_array<const N: usize>(
&self,
path: &str,
) -> Result<&[u8; N], AssetLookupError>
pub fn get_array<const N: usize>( &self, path: &str, ) -> Result<&[u8; N], AssetLookupError>
Borrow an exact-size byte array, reporting both expected and actual lengths on mismatch. Numeric formats should decode explicit endianness; this does not reinterpret memory or impose an implicit wire format.
use ferravex_engine::assets::Bundle;
let mut bundle = Bundle::default();
bundle.insert("level/seed", &123_u32.to_le_bytes())?;
let seed = u32::from_le_bytes(*bundle.get_array::<4>("level/seed")?);
assert_eq!(seed, 123);pub fn names(&self) -> impl Iterator<Item = &str>
pub fn manifest(
&self,
) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
pub fn manifest( &self, ) -> impl ExactSizeIterator + DoubleEndedIterator + FusedIterator
Iterate read-only metadata in ascending canonical path order.
Paths borrow this bundle and are already normalized; checked edits may accept authoring aliases, but the manifest contains only canonical names. No allocation, payload copy or Arc clone is needed. Fingerprints are computed lazily over each yielded asset’s decoded bytes, so a complete traversal scans at most 64 MiB across at most 4096 entries. Results depend only on paths and content, not insertion order or encoding choices.
Retain LiveBundle::current to inspect one generation across reloads.
Collect entries if repeated scans are needed; their paths still borrow
that retained bundle. This does not add a serialized manifest format or
change FXPK0001 encoding. See AssetManifestEntry::fingerprint for the
fixed algorithm and collision limitations.
use ferravex_engine::assets::Bundle;
let mut bundle = Bundle::default();
bundle.apply_edits_checked([
(r".\textures\\flat", Some(&[7; 16][..])),
("./meta//empty", Some(&b""[..])),
])?;
let entries: Vec<_> = bundle.manifest().collect();
assert_eq!(entries.iter().map(|entry| entry.path).collect::<Vec<_>>(),
["meta/empty", "textures/flat"]);
assert_eq!(entries.iter().map(|entry| entry.byte_len).sum::<usize>(),
bundle.decoded_bytes());
let decoded = Bundle::decode(&bundle.encode())?;
assert_eq!(entries, decoded.manifest().collect::<Vec<_>>());