pub trait IconProvider: Debug {
// Required methods
fn icon_name(&self, set: IconSet) -> Option<&str>;
fn icon_svg(&self, set: IconSet) -> Option<&'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
load_custom_icon(). 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::{IconProvider, IconSet};
#[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<&'static [u8]> {
None // No bundled SVGs in this example
}
}