pub trait IconExtractor: Send + Sync {
// Required methods
fn extract_from_path<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn extract_from_url<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn extract_from_extension<'life0, 'life1, 'async_trait>(
&'life0 self,
ext: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn default_app_icon_path(&self) -> &str;
fn default_web_icon_path(&self) -> &str;
fn is_network_available(&self) -> bool;
// Provided methods
fn extract<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn extract_and_process<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn load_default_icon<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Vec<u8>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn get_icon<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cache: &'life1 IconCacheService,
request: &'life2 IconRequest,
level: CacheLevel,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn get_icon_and_update_cache<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cache: &'life1 IconCacheService,
request: &'life2 IconRequest,
level: CacheLevel,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
图标提取器 trait,定义平台原语与跨平台业务默认实现。 平台实现者只需实现 6 个原语方法,业务逻辑由默认实现提供。 默认实现可按需覆盖。
Required Methods§
Sourcefn extract_from_path<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extract_from_path<'life0, 'life1, 'async_trait>(
&'life0 self,
path: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
从本地文件路径提取图标,返回 PNG 格式字节数据。 参数:path - 文件路径(exe, lnk, url, ico, png 等)。 返回:PNG 格式图标字节数据,失败返回 HostApiError。
Sourcefn extract_from_url<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extract_from_url<'life0, 'life1, 'async_trait>(
&'life0 self,
url: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
从网址提取图标(favicon),返回 PNG 格式字节数据。 参数:url - 网址。 返回:PNG 格式图标字节数据,失败返回 HostApiError。
Sourcefn extract_from_extension<'life0, 'life1, 'async_trait>(
&'life0 self,
ext: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extract_from_extension<'life0, 'life1, 'async_trait>(
&'life0 self,
ext: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
从文件扩展名提取系统关联图标,返回 PNG 格式字节数据。 参数:ext - 文件扩展名(如 “.txt”, “.doc”)。 返回:PNG 格式图标字节数据,失败返回 HostApiError。
Sourcefn default_app_icon_path(&self) -> &str
fn default_app_icon_path(&self) -> &str
获取默认应用图标的文件路径。 参数:无。 返回:默认应用图标路径字符串。
Sourcefn default_web_icon_path(&self) -> &str
fn default_web_icon_path(&self) -> &str
获取默认网址图标的文件路径。 参数:无。 返回:默认网址图标路径字符串。
Sourcefn is_network_available(&self) -> bool
fn is_network_available(&self) -> bool
检测当前平台网络是否可用。 参数:无。 返回:网络可用返回 true。
Provided Methods§
Sourcefn extract<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extract<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
根据 IconRequest 提取原始图标数据。 默认实现根据请求类型分发到对应的平台原语方法。 参数:request - 图标请求。 返回:PNG 格式图标字节数据,失败返回 HostApiError。
Sourcefn extract_and_process<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn extract_and_process<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
提取图标并应用后处理:裁剪白边 → 等比缩放到 128×128 上限 → WebP 无损编码(VP8L)。 参数:request - 图标请求。 返回:处理后的 WebP 格式图标字节数据(失败回退 PNG,消费方按字节头嗅探),提取失败返回 HostApiError。
Sourcefn load_default_icon<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Vec<u8>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load_default_icon<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 IconRequest,
) -> Pin<Box<dyn Future<Output = Vec<u8>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
加载默认图标。 默认实现:URL 类型加载默认网址图标,其他类型加载默认应用图标。 参数:request - 图标请求(用于判断类型)。 返回:默认图标的 WebP 字节数据,读取失败返回空 Vec。
Sourcefn get_icon<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cache: &'life1 IconCacheService,
request: &'life2 IconRequest,
level: CacheLevel,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_icon<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cache: &'life1 IconCacheService,
request: &'life2 IconRequest,
level: CacheLevel,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
完整的图标获取流程,包含缓存策略。 默认实现:根据 CacheLevel 执行 L1 → L2 → 提取 → 写回缓存,提取失败返回默认图标。 参数:cache - 图标缓存服务;request - 图标请求;level - 缓存等级。 返回:WebP 格式图标字节数据(回退路径可能为 PNG,消费方按字节头嗅探 MIME),失败返回 HostApiError。
Sourcefn get_icon_and_update_cache<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cache: &'life1 IconCacheService,
request: &'life2 IconRequest,
level: CacheLevel,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_icon_and_update_cache<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
cache: &'life1 IconCacheService,
request: &'life2 IconRequest,
level: CacheLevel,
) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, HostApiError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
强制从磁盘提取图标并更新缓存(跳过缓存读取)。 默认实现:直接提取 → 写回缓存。 参数:cache - 图标缓存服务;request - 图标请求;level - 缓存等级。 返回:WebP 格式图标字节数据,提取失败返回 HostApiError。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".