pub struct IconGenerator { /* private fields */ }Expand description
Builder API for composing multiple TOML icon definitions.
Implementations§
Source§impl IconGenerator
impl IconGenerator
Sourcepub fn source(self, path: impl AsRef<Path>) -> Self
pub fn source(self, path: impl AsRef<Path>) -> Self
Adds a source file. Multiple calls accumulate.
Sourcepub fn enum_name(self, name: &str) -> Self
pub fn enum_name(self, name: &str) -> Self
Sets the enum name override. Replaces any previous value.
Sourcepub fn base_dir(self, path: impl AsRef<Path>) -> Self
pub fn base_dir(self, path: impl AsRef<Path>) -> Self
Sets the base directory. Replaces any previous value.
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.
Sourcepub fn crate_path(self, path: &str) -> Self
pub fn crate_path(self, path: &str) -> Self
Sets the crate path. Replaces any previous value.
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.
Sourcepub fn derive(self, name: &str) -> Self
pub fn derive(self, name: &str) -> Self
Adds an extra derive. Multiple calls accumulate. Duplicates with the
base set (Debug, Clone, Copy, PartialEq, Eq, Hash) are deduplicated.
use native_theme_build::UnwrapOrExit;
native_theme_build::IconGenerator::new()
.source("icons/icons.toml")
.derive("Ord")
.derive("serde::Serialize")
.generate()
.unwrap_or_exit()
.emit_cargo_directives()
.expect("failed to write generated code");Sourcepub fn output_dir(self, path: impl AsRef<Path>) -> Self
pub fn output_dir(self, path: impl AsRef<Path>) -> Self
Sets the output directory. Replaces any previous value.
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).
Sourcepub fn generate(self) -> Result<GenerateOutput, BuildErrors>
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.