Skip to main content

z_icons/
lib.rs

1//! Framework-independent Lucide icons as static SVG data.
2//!
3//! Every icon is a `static` [`Icon`] named after its Lucide file in `SCREAMING_SNAKE_CASE`
4//! (`user` → [`USER`], `arrow-left` → [`ARROW_LEFT`], `grid-2x2` → [`GRID_2X2`]).
5//! No GUI toolkit, allocator, filesystem, parser or renderer is required.
6//!
7//! ```
8//! let bytes: &'static [u8] = z_icons::USER.svg();
9//! let text: &'static str = z_icons::USER.svg_str();
10//! // Pass bytes/text to your toolkit's SVG loader, or export a colored document.
11//! let svg = z_icons::USER.render().size(32, 32).color("#2563eb").to_string();
12//! assert!(svg.contains("#2563eb"));
13//! ```
14//!
15//! Raw SVGs have white strokes for image tinting. [`Icon::render`] defaults to
16//! `currentColor` for inline SVG and can set an explicit color for SVG loaders.
17//! [`Svg`] implements [`core::fmt::Display`], including for allocation-free writers.
18//! Unused static icons can be discarded by the linker. Optional feature `catalog`
19//! enables `all()` and `get()`, retaining the complete set when used.
20//!
21//! Rust code is MIT licensed; Lucide assets are ISC/MIT (see `LICENSE-LUCIDE`).
22
23#![no_std]
24#![forbid(unsafe_code)]
25
26mod svg;
27pub use svg::Svg;
28
29#[cfg(feature = "catalog")]
30mod catalog;
31#[cfg(feature = "catalog")]
32pub use catalog::{all, get};
33
34/// A named, static UTF-8 SVG document. Bundled Lucide icons use a 24×24 viewBox.
35#[derive(Clone, Copy, Debug, PartialEq, Eq)]
36pub struct Icon {
37    name: &'static str,
38    svg: &'static str,
39    bundled: bool,
40}
41
42impl Icon {
43    /// Embed a custom static SVG, for example with `include_str!("icon.svg")`.
44    ///
45    /// The document is trusted application data, not sanitized. To use [`Self::render`],
46    /// it must start with an `<svg ...>` root (leading whitespace is allowed), without
47    /// an XML declaration or doctype. Root options follow normal SVG inheritance;
48    /// explicit child strokes/styles take precedence.
49    pub const fn new(name: &'static str, svg: &'static str) -> Self {
50        Self {
51            name,
52            svg,
53            bundled: false,
54        }
55    }
56
57    pub(crate) const fn bundled(name: &'static str, svg: &'static str) -> Self {
58        Self {
59            name,
60            svg,
61            bundled: true,
62        }
63    }
64
65    /// Icon name, e.g. `"arrow-left"`.
66    pub const fn name(&self) -> &'static str {
67        self.name
68    }
69
70    /// Original SVG bytes, without parsing or allocation. Bundled strokes are white.
71    pub const fn svg(&self) -> &'static [u8] {
72        self.svg.as_bytes()
73    }
74
75    /// Original SVG text, without parsing or allocation.
76    pub const fn svg_str(&self) -> &'static str {
77        self.svg
78    }
79
80    /// A configurable SVG document, using `currentColor` by default.
81    ///
82    /// Use `.color("#fff")` for tintable images, or an explicit color for rasterization.
83    pub const fn render(&self) -> Svg<'_> {
84        Svg::new(self)
85    }
86}
87
88#[rustfmt::skip]
89mod generated;
90pub use generated::*;