simpleicons-rs lets you fetch or embed SVGs from the Simple Icons collection in Rust:
- Runtime lookup by slug.
- Zero‑cost compile‑time constants (no lookup).
- Optional color injection (brand default or any CSS color parseable by
csscolorparser).
cargo add simpleicons-rsImportant
Please read the legal disclaimer before using any icon.
function will return Icon as follow:
pub struct Icon {
pub title: &'static str,
pub slug: &'static str,
pub hex: &'static str,
pub source: &'static str,
pub svg: &'static str,
}Use runtime lookup for flexibility, or a compile‑time constant for zero lookup:
use simpleicons_rs::{slug, SIRUST};
fn main() {
let dynamic = slug("rust").unwrap(); // runtime lookup
let constant = SIRUST; // compile-time constant
println!("{}", dynamic.svg);
println!("{}", constant.svg);
}Error handling:
match simpleicons_rs::slug("not-a-slug") {
Some(icon) => println!("Found {}", icon.title),
None => eprintln!("Icon not found"),
}use simpleicons_rs::slug_colored;
fn main() {
let slug = "rust";
// Official brand color
let brand = slug_colored(slug, "default").unwrap();
// CSS named color
let named = slug_colored(slug, "black").unwrap();
// Hex
let hexed = slug_colored(slug, "#181717").unwrap();
// Any csscolorparser format: #abc, rgb(), rgba(), hsl(), hsla(), etc.
let hsl = slug_colored(slug, "hsl(10 10% 10%)").unwrap();
println!("{}", brand.svg);
}This repo (builder) generates the publishable crate.
git clone https://github.com/cscnk52/simpleicons-rs.git
cd simpleicons-rs
cargo runGenerated crate appears under build/crates.
Then:
cd build/crates
cargo publish --allow-dirty- simpleicons-rs: MIT and CC0-1.0.
- simpleicons-rs-builder: MIT.
- Simple Icons: CC0-1.0 and legal disclaimer.