Skip to main content

IconGenerator

Struct IconGenerator 

Source
pub struct IconGenerator { /* private fields */ }
Expand description

Builder API for composing multiple TOML icon definitions.

Implementations§

Source§

impl IconGenerator

Source

pub fn new() -> Self

Create a new builder.

Source

pub fn source(self, path: impl AsRef<Path>) -> Self

Add a TOML icon definition file.

Source

pub fn enum_name(self, name: &str) -> Self

Override the generated enum name.

Source

pub fn base_dir(self, path: impl AsRef<Path>) -> Self

Set the base directory for theme resolution.

When set, all theme directories (e.g., material/, sf-symbols/) are resolved relative to this path instead of the parent directory of each TOML source file.

When not set and multiple sources have different parent directories, generate() returns an error.

Source

pub fn crate_path(self, path: &str) -> Self

Set the Rust crate path prefix used in generated code.

Defaults to "native_theme". When the default is used, the generated file includes extern crate native_theme; to support Cargo aliases.

Set this to a custom path (e.g. "my_crate::native_theme") when re-exporting native-theme from another crate.

Source

pub fn derive(self, name: &str) -> Self

Add an extra #[derive(...)] trait to the generated enum.

The base set (Debug, Clone, Copy, PartialEq, Eq, Hash) is always emitted. Each call appends one additional derive.

native_theme_build::IconGenerator::new()
    .source("icons/icons.toml")
    .derive("Ord")
    .derive("serde::Serialize")
    .generate()
    .unwrap_or_exit();
Source

pub fn output_dir(self, path: impl AsRef<Path>) -> Self

Set an explicit output directory for the generated .rs file.

When not set, the OUT_DIR environment variable is used (always available during cargo build). Set this when running outside of a build script context (e.g., in integration tests).

Source

pub fn generate(self) -> Result<GenerateOutput, BuildErrors>

Run the full pipeline: load, validate, generate.

Returns a GenerateOutput on success or BuildErrors on failure. Call GenerateOutput::emit_cargo_directives() on the result to write the generated file and emit cargo directives.

Source paths may be absolute or relative. Relative paths are resolved against CARGO_MANIFEST_DIR. When all source paths are absolute, CARGO_MANIFEST_DIR is not required.

§Errors

Returns BuildErrors if CARGO_MANIFEST_DIR is not set and a relative source path is used, or if neither output_dir() nor OUT_DIR is set.

Trait Implementations§

Source§

impl Debug for IconGenerator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for IconGenerator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.