Skip to main content

Crate lucide_icons

Crate lucide_icons 

Source
Expand description

Auto-generated rust icon definitions for lucide icons version 1.12.0

This library provides an Icon enum which contains all lucide icon variants:

use lucide_icons::Icon;

fn main() {
    let icon = Icon::Anvil;
    assert_eq!(format!("{icon}"), String::from("anvil"));
    println!("unicode = {}", char::from(icon));
}

Additionally, the underlying lucide ttf bytes are available through the LUCIDE_FONT_BYTES constant.

§Iced

With the iced feature, iced compatibility can be enabled. This means, Icon variants can directly be converted to iced widgets and for every lucide icon variant there will be a named function which returns an icon widget.

use lucide_icons::{LUCIDE_FONT_BYTES, iced::icon_anvil};

fn setup_application() {
    let settings = iced::Settings {
        // add bundled font to iced
        fonts: vec![LUCIDE_FONT_BYTES.into()],
        ..Default::default()
    };

    // run app with settings...
}

fn view() -> iced::Element<'_, Message, Theme, iced::Renderer> {
    iced::widget::column![
        // named widget function per icon
        icon_anvil(),
        // widget function per variant
        Icon::Anvil.into()
    ].into()
}

§Serde

With the serde feature, the library also provides serialization/deserialization for the Icon enum by an icon name.

use lucide_icons::Icon;

#[derive(serde::Serialize)]
struct IconWrapper {
    icon: Icon
}

fn to_json() {
    let icon = IconWrapper { icon: Icon::ArrowUpNarrowWide };
    let str = serde_json::to_string(&icon).expect("should serialize");
    assert_eq!(str, "{\"icon\":\"arrow-up-narrow-wide\"}");
}

Enums§

Icon
Representation of a lucide icon

Constants§

LUCIDE_FONT_BYTES
Bytes of the lucide font