Skip to main content

Assets

Struct Assets 

Source
pub struct Assets<T: 'static + Send + Sync> { /* private fields */ }
Expand description

Storage for raw CPU-side assets of type T.

Assets are inserted by name and looked up by either name or RawAssetHandle. When an asset is inserted or updated its handle is pushed onto the dirty queue, which the sync system drains each tick to upload changed assets to the GPU.

Implementations§

Source§

impl<T: 'static + Send + Sync> Assets<T>

Source

pub fn new() -> Self

Source

pub fn insert(&mut self, name: &str, asset: T) -> RawAssetHandle

Insert asset under name, returning its handle.

If an asset with the same name already exists, its data is replaced in-place: the same slot-map entry (and therefore the same handle) is reused, so any code that already holds a Handle or RawAssetHandle for this asset continues to work correctly. The handle is re-queued so the sync system re-uploads the new data.

Source

pub fn get(&self, handle: RawAssetHandle) -> Option<&T>

Look up an asset by its raw handle.

Source

pub fn get_mut(&mut self, handle: RawAssetHandle) -> Option<&mut T>

Mutably look up an asset by its raw handle.

Source

pub fn get_by_name(&self, name: &str) -> Option<&T>

Look up an asset by its name.

Source

pub fn get_mut_by_name(&mut self, name: &str) -> Option<&mut T>

Mutably look up an asset by its name.

Source

pub fn get_handle_by_name(&self, name: &str) -> Option<RawAssetHandle>

Look up an asset handle by its name.

Source

pub fn take_dirty(&mut self) -> Vec<RawAssetHandle>

Drain and return all handles currently in the dirty queue.

Called by the asset sync system each tick.

Source

pub fn remove(&mut self, handle: RawAssetHandle) -> Option<T>

Remove an asset by handle, returning the value if it existed.

Source

pub fn remove_by_name(&mut self, name: &str) -> Option<T>

Remove an asset by name, returning the value if it existed.

Source

pub fn take_removed(&mut self) -> Vec<RawAssetHandle>

Drain and return all handles removed since the last call.

Called by the asset sync system each tick to evict stale processed assets.

Source

pub fn dirty_is_empty(&self) -> bool

Returns true if the dirty queue is empty.

Source

pub fn dirty_len(&self) -> usize

Returns the number of handles currently in the dirty queue.

Source

pub fn requeue(&mut self, handles: Vec<RawAssetHandle>)

Push handles back onto the dirty queue so they are retried next tick.

Source

pub fn iter(&self) -> impl Iterator<Item = (RawAssetHandle, &T)>

Iterate over all assets by handle.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (RawAssetHandle, &mut T)>

Mutably iterate over all assets by handle.

Source

pub fn names(&self) -> impl Iterator<Item = (&str, RawAssetHandle)>

Iterate over (name, handle) pairs for every named asset.

Source

pub fn name_for_handle(&self, handle: RawAssetHandle) -> Option<&str>

Trait Implementations§

Source§

impl<'a, T: 'static + Send + Sync> IntoIterator for &'a Assets<T>

Source§

type Item = (RawAssetHandle, &'a T)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, RawAssetHandle, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T: 'static + Send + Sync> IntoIterator for &'a mut Assets<T>

Source§

type Item = (RawAssetHandle, &'a mut T)

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, RawAssetHandle, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Assets<T>

§

impl<T> RefUnwindSafe for Assets<T>
where T: RefUnwindSafe,

§

impl<T> Send for Assets<T>

§

impl<T> Sync for Assets<T>

§

impl<T> Unpin for Assets<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Assets<T>

§

impl<T> UnwindSafe for Assets<T>
where T: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Component for T
where T: Send + Sync + 'static,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more