Skip to content

cscnk52/simpleicons-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simpleicons-rs banner

simpleicons-rs

Access high‑quality Simple Icons SVGs directly from your Rust code.

Crates.io Docs MIT licensed

Overview

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).

Installation

cargo add simpleicons-rs

Usage

Important

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,
}

Plain SVG

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"),
}

Colored SVG

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);
}

Build

This repo (builder) generates the publishable crate.

git clone https://github.com/cscnk52/simpleicons-rs.git
cd simpleicons-rs
cargo run

Generated crate appears under build/crates. Then:

cd build/crates
cargo publish --allow-dirty

License

  • simpleicons-rs: MIT and CC0-1.0.
  • simpleicons-rs-builder: MIT.
  • Simple Icons: CC0-1.0 and legal disclaimer.

About

Simple Icons Rust crate

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages