Skip to main content

AssetManager

Struct AssetManager 

Source
pub struct AssetManager { /* private fields */ }
Expand description

Cancelable budgeted LRU asset cache wired directly to ResourceAccountant for leak attribution.

Implementations§

Source§

impl AssetManager

Cancelable loading, deterministic LRU budget enforcement, and ResourceAccountant lifecycle tracking for AssetManager.

Source

pub fn with_budget(budget: AssetBudgetConfig) -> Self

Creates an empty AssetManager enforcing explicit RAM and VRAM byte budgets.

§Arguments
  • AssetBudgetConfig - Maximum resident RAM and VRAM byte budgets.
§Returns
  • Self - Configured empty asset manager.
Source

pub fn is_handle_valid(&self, handle: AssetHandle) -> bool

Checks whether handle currently resolves to a live occupied slot with matching generation.

§Arguments
  • AssetHandle - Candidate generation-stamped asset handle.
§Returns
  • bool - true when handle points to a live entry.
Source

pub fn begin_load<KeyType>( &mut self, key: KeyType, owner: ResourceOwnerId, storage: AssetStorageKind, accountant: &mut ResourceAccountant, ) -> AssetHandle
where KeyType: Into<String>,

Starts a cancelable asset load request and registers its pending AsyncTask under owner in accountant.

§Arguments
  • KeyType - Logical asset key (URI, path, or hash).
  • ResourceOwnerId - Single authoritative resource owner.
  • AssetStorageKind - Target residency domain (Ram, Vram, or Hybrid).
  • &mut ResourceAccountant - Framework resource accountant tracking the pending task.
§Returns
  • AssetHandle - Generation-stamped handle for completing, canceling, or querying the asset.
Source

pub fn cancel_load( &mut self, handle: AssetHandle, accountant: &mut ResourceAccountant, ) -> bool

Cancels an in-flight pending load, releases its AsyncTask from accountant, and invalidates handle.

§Arguments
  • AssetHandle - Handle returned by begin_load.
  • &mut ResourceAccountant - Resource accountant releasing the pending task.
§Returns
  • bool - true when a pending load was canceled.
Source

pub fn complete_load( &mut self, handle: AssetHandle, payload: Vec<u8>, vram_bytes: usize, accountant: &mut ResourceAccountant, ) -> Result<(), AssetError>

Completes a pending asset load, enforcing RAM/VRAM budgets via deterministic LRU eviction and registering allocations in accountant.

§Arguments
  • AssetHandle - Pending load handle returned by begin_load.
  • Vec<u8> - Decoded CPU payload bytes (discarded for AssetStorageKind::Vram).
  • usize - GPU VRAM byte footprint (ignored for AssetStorageKind::Ram).
  • &mut ResourceAccountant - Resource accountant updated with released tasks, evictions, and live allocations.
§Returns
  • Result<(), AssetError> - Ok(()) once resident, or InvalidHandle / ExceedsBudget on failure.
Source

pub fn insert_ready<KeyType>( &mut self, key: KeyType, owner: ResourceOwnerId, storage: AssetStorageKind, payload: Vec<u8>, vram_bytes: usize, accountant: &mut ResourceAccountant, ) -> Result<AssetHandle, AssetError>
where KeyType: Into<String>,

Synchronously inserts a ready asset under owner, enforcing budgets and registering with accountant.

§Arguments
  • KeyType - Logical asset key.
  • ResourceOwnerId - Single authoritative resource owner.
  • AssetStorageKind - Memory residency domain.
  • Vec<u8> - Decoded CPU payload bytes.
  • usize - GPU VRAM byte footprint.
  • &mut ResourceAccountant - Resource accountant receiving lifecycle updates.
§Returns
  • Result<AssetHandle, AssetError> - Live generation-stamped handle or budget error.
Source

pub fn get(&mut self, handle: AssetHandle) -> Option<&[u8]>

Looks up a resident asset payload by generation-stamped handle, updating LRU recency and hit/miss counters.

§Arguments
  • AssetHandle - Generation-stamped asset handle.
§Returns
  • Option<&[u8]> - Borrowed payload slice when resident and valid.
Source

pub fn get_by_key(&mut self, key: &str) -> Option<(AssetHandle, &[u8])>

Looks up a resident asset by logical string key, refreshing its LRU timestamp on hit.

§Arguments
  • &str - Logical asset key.
§Returns
  • Option<(AssetHandle, &[u8])> - Live handle and borrowed payload slice on hit.
Source

pub fn set_pinned(&mut self, handle: AssetHandle, pinned: bool) -> bool

Pins or unpins a live asset to protect or expose it during automatic LRU budget eviction.

§Arguments
  • AssetHandle - Generation-stamped asset handle.
  • bool - true to pin against LRU eviction, false to allow eviction.
§Returns
  • bool - true if the handle was valid and updated.
Source

pub fn release( &mut self, handle: AssetHandle, accountant: &mut ResourceAccountant, ) -> bool

Explicitly releases one asset and removes all associated entries from accountant.

§Arguments
  • AssetHandle - Generation-stamped asset handle.
  • &mut ResourceAccountant - Resource accountant receiving release notifications.
§Returns
  • bool - true when the asset existed and was released.
Source

pub fn evict_to_budget( &mut self, target_ram_bytes: usize, target_vram_bytes: usize, accountant: &mut ResourceAccountant, ) -> usize

Evicts unpinned least-recently-used assets until RAM and VRAM usage fall within the requested target ceilings.

§Arguments
  • usize - Target maximum resident CPU RAM bytes.
  • usize - Target maximum resident GPU VRAM bytes.
  • &mut ResourceAccountant - Resource accountant receiving release calls for each evicted entry.
§Returns
  • usize - Number of assets evicted.
Source

pub fn release_owner( &mut self, owner: ResourceOwnerId, now_ms: u64, retire_fence_id: u64, accountant: &mut ResourceAccountant, ) -> usize

Releases every asset owned by owner, deferring VRAM retirement when retire_fence_id is still in flight on the GPU.

§Arguments
  • ResourceOwnerId - Destroyed owner identifier.
  • u64 - Monotonic destruction timestamp in milliseconds.
  • u64 - GPU fence required before VRAM release (0 for immediate release).
  • &mut ResourceAccountant - Resource accountant recording owner destruction and releases.
§Returns
  • usize - Number of asset entries removed from the manager.
Source

pub fn stats(&self) -> AssetManagerStats

Captures a structured telemetry snapshot of current asset counts, memory footprints, and cache statistics.

§Returns
  • AssetManagerStats - Current asset manager telemetry snapshot.
Source§

impl AssetManager

Source

pub fn get_budget(&self) -> AssetBudgetConfig

Source

pub fn get_mut_budget(&mut self) -> &mut AssetBudgetConfig

Source

pub fn set_budget(&mut self, val: AssetBudgetConfig) -> &mut Self

Source

pub fn get_ram_used_bytes(&self) -> usize

Source

pub fn get_mut_ram_used_bytes(&mut self) -> &mut usize

Source

pub fn set_ram_used_bytes(&mut self, val: usize) -> &mut Self

Source

pub fn get_vram_used_bytes(&self) -> usize

Source

pub fn get_mut_vram_used_bytes(&mut self) -> &mut usize

Source

pub fn set_vram_used_bytes(&mut self, val: usize) -> &mut Self

Source

pub fn get_hits(&self) -> u64

Source

pub fn get_mut_hits(&mut self) -> &mut u64

Source

pub fn set_hits(&mut self, val: u64) -> &mut Self

Source

pub fn get_misses(&self) -> u64

Source

pub fn get_mut_misses(&mut self) -> &mut u64

Source

pub fn set_misses(&mut self, val: u64) -> &mut Self

Source

pub fn get_evictions(&self) -> u64

Source

pub fn get_mut_evictions(&mut self) -> &mut u64

Source

pub fn set_evictions(&mut self, val: u64) -> &mut Self

Source

pub fn get_cancellations(&self) -> u64

Source

pub fn get_mut_cancellations(&mut self) -> &mut u64

Source

pub fn set_cancellations(&mut self, val: u64) -> &mut Self

Trait Implementations§

Source§

impl Clone for AssetManager

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AssetManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AssetManager

Default empty AssetManager configured with default RAM and VRAM budgets.

Source§

fn default() -> Self

Creates an empty AssetManager with default budgets.

§Returns
  • Self - Empty budgeted asset manager.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.