pub trait GraphicsResolver: Send + Sync {
// Required methods
fn resolve(
&self,
request: &GraphicsResolveRequest,
) -> Result<ImageFile, GraphicsResolveError>;
fn read(&self, file: &ImageFile) -> Result<Vec<u8>, GraphicsResolveError>;
}Expand description
The graphics resolver: a service that finds and reads image files,
which a host contributes to the service slot RESOLVER_SLOT. See the
module documentation.
§Examples
use std::sync::Arc;
use flm_core::core::registry::RegistryBuilder;
use flm_core::stdlib::features::graphics::{
GraphicsResolveError, GraphicsResolveRequest, GraphicsResolver, ImageFile, RESOLVER_SLOT,
};
/// Every path refers to the same one-byte PNG file.
struct OneFile;
impl GraphicsResolver for OneFile {
fn resolve(&self, request: &GraphicsResolveRequest) -> Result<ImageFile, GraphicsResolveError> {
Ok(ImageFile::new("the-file", "image/png", request.path.clone()))
}
fn read(&self, _file: &ImageFile) -> Result<Vec<u8>, GraphicsResolveError> {
Ok(vec![0])
}
}
let mut builder = RegistryBuilder::new();
builder.contribute_to(RESOLVER_SLOT, Arc::new(OneFile) as Arc<dyn GraphicsResolver>);Required Methods§
Sourcefn resolve(
&self,
request: &GraphicsResolveRequest,
) -> Result<ImageFile, GraphicsResolveError>
fn resolve( &self, request: &GraphicsResolveRequest, ) -> Result<ImageFile, GraphicsResolveError>
Returns the file that request.path refers to, found from
request.origin.
§Errors
A GraphicsResolveError in the resolver’s own words when no file is
found or the file cannot be read.
Sourcefn read(&self, file: &ImageFile) -> Result<Vec<u8>, GraphicsResolveError>
fn read(&self, file: &ImageFile) -> Result<Vec<u8>, GraphicsResolveError>
Returns the content of file, a file this resolver returned. The
feature calls it again whenever it needs the content.
§Errors
A GraphicsResolveError in the resolver’s own words when the file
can no longer be read.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".