pub struct NativeAssetManager { /* private fields */ }Expand description
A concrete AssetManager for native desktop targets that loads from the local filesystem.
The cache is read on every render frame (lock-free via ArcSwap::load()) but written
at most once per URL after disk I/O completes. rcu() atomically inserts the result
without blocking concurrent render-loop readers.
Implementations§
Trait Implementations§
Source§impl AssetManager for NativeAssetManager
impl AssetManager for NativeAssetManager
Source§fn load_image(&self, url: &str) -> AssetState<Arc<Vec<u8>>>
fn load_image(&self, url: &str) -> AssetState<Arc<Vec<u8>>>
Return the cached asset state for url.
Fast path: lock-free snapshot read via ArcSwap::load().
Slow path (cache miss): atomically insert a Loading sentinel via rcu(),
then spawn a background thread for I/O. The rcu() closure may execute
more than once under contention, so already_tracked is determined by
whether the closure actually inserted the Loading entry (detected by checking
the returned map). This prevents duplicate I/O threads for the same URL.
FIX #5: The previous implementation set already_tracked inside the rcu
closure body, which is incorrect because rcu retries the closure on
contention — the bool would reflect only the last execution. The fix uses
the fast-path check result plus the atomic rcu insertion to determine
whether a thread must be spawned, making the logic correct under concurrency.
Source§fn preload_image(&self, url: &str)
fn preload_image(&self, url: &str)
Trigger a background load of url without waiting for the result.
FIX #6: The previous implementation had a bare fast-path check followed
by an unconditional thread spawn, allowing two concurrent calls for the
same URL to both spawn I/O threads. Now uses the same rcu-based insertion
guard as load_image to ensure exactly one thread is spawned per URL.
Auto Trait Implementations§
impl Freeze for NativeAssetManager
impl RefUnwindSafe for NativeAssetManager
impl Send for NativeAssetManager
impl Sync for NativeAssetManager
impl Unpin for NativeAssetManager
impl UnsafeUnpin for NativeAssetManager
impl UnwindSafe for NativeAssetManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().