Struct LiveBundle
pub struct LiveBundle { /* private fields */ }Expand description
Existing readers retain their Arc until the next successful reload is adopted.
Implementations§
§impl LiveBundle
impl LiveBundle
pub fn current(&self) -> Arc<Bundle>
pub fn generation(&self) -> u64
pub fn reload(&mut self, bytes: &[u8]) -> Result<(), AssetError>
pub fn reload_checked<E>(
&mut self,
bytes: &[u8],
validate: impl FnOnce(&Bundle) -> Result<(), E>,
) -> Result<BundleDiff, BundleUpdateError<E>>
pub fn reload_checked<E>( &mut self, bytes: &[u8], validate: impl FnOnce(&Bundle) -> Result<(), E>, ) -> Result<BundleDiff, BundleUpdateError<E>>
Decode and validate a candidate before publishing it. A validator can require typed assets or check an application’s schema. It runs once after decoding, even for unchanged content; it is never called on decode failure.
Returns the existing sorted content diff. Unlike legacy Self::reload,
an unchanged candidate retains both the generation and current Arc. A
changed candidate increments the generation exactly once. Any failure,
including validation or generation overflow, preserves the last good bundle.
use ferravex_engine::assets::{AssetLookupError, Bundle, LiveBundle};
let mut authored = Bundle::default();
authored.insert("level/seed", &42_u32.to_le_bytes())?;
let validate = |bundle: &Bundle| -> Result<(), AssetLookupError> {
bundle.get_array::<4>("level/seed")?;
Ok(())
};
let mut live = LiveBundle::default();
let diff = live.reload_checked(&authored.encode(), validate)?;
assert_eq!(diff.added, ["level/seed"]);
let generation = live.generation();
authored.insert("level/seed", b"bad")?;
assert!(live.reload_checked(&authored.encode(), validate).is_err());
assert_eq!(live.generation(), generation);
assert_eq!(live.current().get_array::<4>("level/seed")?, &42_u32.to_le_bytes());pub fn apply_edits_checked<'a, E>(
&mut self,
edits: impl IntoIterator<Item = (&'a str, Option<&'a [u8]>)>,
validate: impl FnOnce(&Bundle) -> Result<(), E>,
) -> Result<BundleDiff, BundleUpdateError<E>>
pub fn apply_edits_checked<'a, E>( &mut self, edits: impl IntoIterator<Item = (&'a str, Option<&'a [u8]>)>, validate: impl FnOnce(&Bundle) -> Result<(), E>, ) -> Result<BundleDiff, BundleUpdateError<E>>
Apply normalized edits and validate the whole candidate before publication.
Reuses Bundle::apply_edits_checked, including ordered edits and
intermediate limits. Validation sees the final candidate only. Generation,
reader retention and no-op behavior match Self::reload_checked.
use ferravex_engine::assets::{AssetLookupError, Bundle, LiveBundle};
let validate = |bundle: &Bundle| -> Result<(), AssetLookupError> {
bundle.get_text("meta/title")?;
Ok(())
};
let mut live = LiveBundle::default();
live.apply_edits_checked([
(r".\meta\title", Some(&b"My game"[..])),
], validate)?;
let old = live.current();
assert!(live.apply_edits_checked([("meta/title", None)], validate).is_err());
assert!(std::sync::Arc::ptr_eq(&old, &live.current()));