Getting started

oxblade-icons Alpha Rust

This page adds oxblade-icons and a generated icon set to a Rust project and renders a first icon.

Install

Add the renderer and the icon set you want. The example uses Lucide from its source repository:

[dependencies]
oxblade-icons = "0.1"
oxblade-lucide = { git = "https://github.com/bowerbird-si/oxblade-icon-sets" }

oxblade-heroicons comes from the same repository. The blade feature (on by default) adds the oxblade template integration; laravel adds the service provider. See the features table.

Render an icon

Build a registry once, at startup, and keep it for the life of the program:

use oxblade_icons::{Attributes, Icons, icon_set};

fn main() -> oxblade_icons::Result<()> {
    let icons = Icons::builder()
        .set(icon_set!(oxblade_lucide))
        .class("icon")
        .build()?;

    let svg = icons.svg("lucide-map-pin", "w-4", Attributes::new().decorative())?;
    println!("{svg}");
    Ok(())
}

icon_set!(oxblade_lucide) turns the generated crate into a registered set with the name lucide and the prefix lucide. The name lucide-map-pin means "the map-pin icon in the set whose prefix is lucide". The output is the Lucide SVG with class="icon w-4" and aria-hidden="true" added to its <svg> element.

build() checks the configuration: set names and prefixes must be unique and well-formed, and every fallback must resolve. A mistake fails at startup instead of on a page.

Next