pub struct Handle<T: ?Sized> { /* private fields */ }
Expand description
A handle on an asset.
It can be obtained through an AssetCache
.
If feature hot-reloading
is used, this structure may wrap a RwLock
, so
assets can be written to be reloaded. As such, any number of read guard can
exist at the same time, but none can exist while reloading an asset.
You can use this structure to reference an asset directly. However you can only get references to this type, never own it. If you don’t want to deal with lifetimes, you can:
Implementations§
Source§impl<T: ?Sized> Handle<T>
impl<T: ?Sized> Handle<T>
Sourcepub fn read(&self) -> AssetReadGuard<'_, T>
pub fn read(&self) -> AssetReadGuard<'_, T>
Locks the pointed asset for reading.
If hot-reloading is disabled for T
or globally, no reloading can occur
so there is no actual lock. In these cases, calling this function does
not involve synchronisation.
Returns a RAII guard which will release the lock once dropped.
Sourcepub fn id(&self) -> &SharedString
pub fn id(&self) -> &SharedString
Returns the id of the asset.
Sourcepub fn as_untyped(&self) -> &UntypedHandlewhere
T: Storable,
pub fn as_untyped(&self) -> &UntypedHandlewhere
T: Storable,
Returns an untyped version of the handle.
Sourcepub fn weak(&self) -> WeakHandle<T>
pub fn weak(&self) -> WeakHandle<T>
Make a WeakHandle
that points to this handle.
Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Gets the number of strong (ArcHandle
) pointers to this allocation.
Sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
Gets the number of WeakHandle
pointers to this allocation.
Sourcepub fn reload_watcher(&self) -> ReloadWatcher<'_>
pub fn reload_watcher(&self) -> ReloadWatcher<'_>
Returns a ReloadWatcher
that can be used to check whether this asset
was reloaded.
§Example
use assets_manager::{AssetCache, ReloadWatcher};
let cache = AssetCache::new("assets")?;
let asset = cache.load::<String>("common.some_text")?;
let mut watcher = asset.reload_watcher();
// The handle has just been created, so `reloaded` returns false
assert!(!watcher.reloaded());
loop {
if watcher.reloaded() {
println!("The asset was reloaded !")
}
}
Sourcepub fn last_reload_id(&self) -> ReloadId
pub fn last_reload_id(&self) -> ReloadId
Returns the last ReloadId
associated with this asset.
It is only meaningful when compared to other ReloadId
s returned by the
same handle or to ReloadId::NEVER
.
Sourcepub fn reloaded_global(&self) -> bool
pub fn reloaded_global(&self) -> bool
Returns true
if the asset has been reloaded since last call to this
method with any handle on this asset.
Note that this method and reload_watcher
are totally independant,
and the result of the two functions do not depend on whether the other
was called.