Crate icondata

source ·
Expand description

This crate provides a collection of icons in the form of SVG data and an enum to select them. It re-exports all icons from the icondata_* crates.

The Icon enum can be converted into an IconData struct, which contains the SVG data used by a component library.

Getting Started

  1. Add the latest version of this crate to your Cargo.toml:
[dependencies]
# .... Other dependencies ....
icondata = "..."
# .... Other dependencies ....
  1. Set the ICONDATA_MANIFEST_DIR environment variable to the path of your Icondata.toml file: This can be done in multiple ways, but the recommended way is to set it in .cargo/config.toml (This assumes that your Icondata.toml file is in the root of your project):
[env]
ICONDATA_MANIFEST_DIR = { value = "", relative = true }
  1. In order to not clog the namespace and to minimize binary sizes, Icons are imported individually by enabling them in the Icondata.toml file. Please refer to the documentation of the Icondata Manifest for more information.

    Create an Icondata.toml file in the root of your project, and include icons.

    Icons can be searched with the icon index. Here is a basic example:

icons = ["AiAlertFilled", "BsBuildingDown"]
  1. Import and use the icons in your code:
use icondata::*;

let icon = BsBuildingDown;
let icon = AiAlertFilled;

Icondata Manifest

The Icondata manifest is a TOML file named Icondata.toml that is usually placed in the root of your project/workspace (but can be placed anyhwere). The format of this file is currently very simple, but may be extended in the future:

include-all = false # If set to `true`, all icons will be included
                    # (takes precedence over `icons` field).
                    # Can be useful for testing many icons,
                    # but won't make `rust-analyzer` happy. 
                    # It is very important to set `lto = true` in your
                    # `Cargo.toml` when using this feature,
                    # otherwise your binary size will be huge.

icons = ["MyIcon1", "MyIcon2", ...] # Array of icons include.

Environment Variables

  • ICONDATA_MANIFEST_DIR: Required to use the Icondata manifest. It is recommended to set it in the .cargo/config.toml file of your project:
[env]
ICONDATA_MANIFEST_DIR = { value = "path/to/dir", relative = true }
  • ICONDATA_INCLUDE_ALL: If set to true or something other than 0, all icons will be included. Takes precedence over the Icondata manifest.

Re-exports

  • pub use icondata_ai::AiIcon::*;
  • pub use icondata_bi::BiIcon::*;
  • pub use icondata_bs::BsIcon::*;
  • pub use icondata_cg::CgIcon::*;
  • pub use icondata_ch::ChIcon::*;
  • pub use icondata_fa::FaIcon::*;
  • pub use icondata_fi::FiIcon::*;
  • pub use icondata_hi::HiIcon::*;
  • pub use icondata_im::ImIcon::*;
  • pub use icondata_io::IoIcon::*;
  • pub use icondata_lu::LuIcon::*;
  • pub use icondata_oc::OcIcon::*;
  • pub use icondata_ri::RiIcon::*;
  • pub use icondata_si::SiIcon::*;
  • pub use icondata_tb::TbIcon::*;
  • pub use icondata_ti::TiIcon::*;
  • pub use icondata_vs::VsIcon::*;
  • pub use icondata_wi::WiIcon::*;

Enums