Struct LiveBundle

pub struct LiveBundle { /* private fields */ }
Expand description

Existing readers retain their Arc until the next successful reload is adopted.

Implementations§

§

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>>

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>>

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()));

Trait Implementations§

§

impl Default for LiveBundle

§

fn default() -> LiveBundle

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.