pub trait IconProvider: Debug {
// Required methods
fn icon_name(&self, set: IconSet) -> Option<&str>;
fn icon_svg(&self, set: IconSet) -> Option<Cow<'static, [u8]>>;
}Expand description
Trait for types that map icon identifiers to platform-specific names and SVG data.
Implement this trait on an enum to make its variants loadable via
the typed per-set loaders in crate::icons. The typical pattern is
for each enum variant to represent an icon role, with icon_name() returning
the platform-specific identifier and icon_svg() returning embedded SVG bytes.
The native-theme-build crate can auto-generate implementations from TOML
definitions at build time, so manual implementation is only needed for
special cases.
IconRole implements this trait, delegating to the built-in icon mappings.
§Object Safety
This trait is object-safe (only requires Debug as a supertrait).
Box<dyn IconProvider> works for dynamic dispatch.
§Examples
use native_theme::theme::{IconProvider, IconSet};
use std::borrow::Cow;
#[derive(Debug)]
enum MyIcon { Play, Pause }
impl IconProvider for MyIcon {
fn icon_name(&self, set: IconSet) -> Option<&str> {
match (self, set) {
(MyIcon::Play, IconSet::SfSymbols) => Some("play.fill"),
(MyIcon::Play, IconSet::Material) => Some("play_arrow"),
(MyIcon::Pause, IconSet::SfSymbols) => Some("pause.fill"),
(MyIcon::Pause, IconSet::Material) => Some("pause"),
_ => None,
}
}
fn icon_svg(&self, _set: IconSet) -> Option<Cow<'static, [u8]>> {
None // No bundled SVGs in this example
}
}Required Methods§
Trait Implementations§
Source§impl<'a> From<&'a dyn IconProvider> for IconId<'a>
impl<'a> From<&'a dyn IconProvider> for IconId<'a>
Source§fn from(provider: &'a dyn IconProvider) -> Self
fn from(provider: &'a dyn IconProvider) -> Self
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".