pub trait BytesLoader {
// Required methods
fn id(&self) -> &str;
fn load(&self, ctx: &Context, uri: &str) -> BytesLoadResult;
fn forget(&self, uri: &str);
fn forget_all(&self);
fn byte_size(&self) -> usize;
// Provided methods
fn end_pass(&self, pass_index: u64) { ... }
fn has_pending(&self) -> bool { ... }
}
Expand description
Represents a loader capable of loading raw unstructured bytes from somewhere, e.g. from disk or network.
It should also provide any subsequent loaders a hint for what the bytes may
represent using BytesPoll::Ready::mime
, if it can be inferred.
Implementations are expected to cache at least each URI
.
Required Methods§
Sourcefn id(&self) -> &str
fn id(&self) -> &str
Unique ID of this loader.
To reduce the chance of collisions, use generate_loader_id
for this.
Sourcefn load(&self, ctx: &Context, uri: &str) -> BytesLoadResult
fn load(&self, ctx: &Context, uri: &str) -> BytesLoadResult
Try loading the bytes from the given uri.
Implementations should call ctx.request_repaint
to wake up the ui
once the data is ready.
The implementation should cache any result, so that calling this is immediate-mode safe.
§Errors
This may fail with:
LoadError::NotSupported
if the loader does not support loadinguri
.LoadError::Loading
if the loading process failed.
Sourcefn forget(&self, uri: &str)
fn forget(&self, uri: &str)
Forget the given uri
.
If uri
is cached, it should be evicted from cache,
so that it may be fully reloaded.
Sourcefn forget_all(&self)
fn forget_all(&self)
Forget all URIs ever given to this loader.
If the loader caches any URIs, the entire cache should be cleared, so that all of them may be fully reloaded.
Provided Methods§
Sourcefn end_pass(&self, pass_index: u64)
fn end_pass(&self, pass_index: u64)
Implementations may use this to perform work at the end of a frame, such as evicting unused entries from a cache.
Sourcefn has_pending(&self) -> bool
fn has_pending(&self) -> bool
Returns true
if some data is currently being loaded.