pub struct ThumbnailCache {
pub config: ThumbnailCacheConfig,
/* private fields */
}Expand description
An in-memory thumbnail request queue + LRU cache.
This type is renderer-agnostic: the application is expected to:
- call
advance_frameonce per UI frame, - drive visibility by calling
request_visiblefor entries that are currently visible, - drain requests via
take_requests, decode/upload thumbnails in user code, then callfulfill, - destroy evicted GPU textures from
take_pending_destroys.
Fields§
§config: ThumbnailCacheConfigCache configuration.
Implementations§
Source§impl ThumbnailCache
impl ThumbnailCache
Sourcepub fn new(config: ThumbnailCacheConfig) -> Self
pub fn new(config: ThumbnailCacheConfig) -> Self
Create a new cache with the given config.
Sourcepub fn advance_frame(&mut self)
pub fn advance_frame(&mut self)
Advance per-frame bookkeeping.
Call this once per UI frame before issuing visibility requests.
Sourcepub fn frame_index(&self) -> u64
pub fn frame_index(&self) -> u64
Returns the internal frame counter.
Sourcepub fn request_visible(&mut self, path: &Path, max_size: [u32; 2])
pub fn request_visible(&mut self, path: &Path, max_size: [u32; 2])
Request a thumbnail for a visible file.
If the thumbnail is not already cached, a request may be queued depending on the per-frame request budget.
Sourcepub fn texture_id(&self, path: &Path) -> Option<TextureId>
pub fn texture_id(&self, path: &Path) -> Option<TextureId>
Returns the cached texture id for a path, if available.
Sourcepub fn take_requests(&mut self) -> Vec<ThumbnailRequest>
pub fn take_requests(&mut self) -> Vec<ThumbnailRequest>
Drain queued thumbnail requests.
Drained requests are marked as “in flight” until fulfill is called.
Sourcepub fn fulfill(
&mut self,
path: &Path,
result: Result<TextureId, String>,
_max_size: [u32; 2],
)
pub fn fulfill( &mut self, path: &Path, result: Result<TextureId, String>, _max_size: [u32; 2], )
Complete a request with either a ready texture id or an error string.
Returns any evicted texture ids that should be destroyed by the renderer.
Sourcepub fn fulfill_request(
&mut self,
req: &ThumbnailRequest,
result: Result<TextureId, String>,
)
pub fn fulfill_request( &mut self, req: &ThumbnailRequest, result: Result<TextureId, String>, )
Complete a previously issued request.
Sourcepub fn maintain(&mut self, backend: &mut ThumbnailBackend<'_>)
pub fn maintain(&mut self, backend: &mut ThumbnailBackend<'_>)
Process queued requests and perform pending destroys.
This is a convenience helper for applications that want dear-file-browser to drive the
request lifecycle:
- Decodes queued requests using
ThumbnailProvider, - Uploads them using
ThumbnailRenderer, - Fulfills the cache, and
- Destroys evicted/replaced GPU textures via the renderer.
If you prefer to manage decoding/upload externally, you can instead use
take_requests, fulfill_request, and
take_pending_destroys.
Sourcepub fn take_pending_destroys(&mut self) -> Vec<TextureId>
pub fn take_pending_destroys(&mut self) -> Vec<TextureId>
Drain GPU textures that should be destroyed after eviction or replacement.
Trait Implementations§
Source§impl Clone for ThumbnailCache
impl Clone for ThumbnailCache
Source§fn clone(&self) -> ThumbnailCache
fn clone(&self) -> ThumbnailCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more