Skip to main content

GenerateWebfontsResult

Struct GenerateWebfontsResult 

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

Result of a successful generateWebfonts call. Exposes the generated font bytes (or null for formats that were not requested) and methods to render the CSS and HTML preview.

Implementations§

Source§

impl GenerateWebfontsResult

Source

pub fn add( &mut self, path: String, name: Option<String>, variant: Option<&str>, ) -> Result<()>

Append a new file and regenerate. Families require an existing target variant. name overrides the file stem. Requires incremental generation and inherits Self::regenerate’s validation, callback restrictions and write/failure semantics.

Source

pub fn update(&mut self, path: String, name: Option<String>) -> Result<()>

Re-read an existing file in every consuming design, preserving its position. An absent name preserves the glyph name. Inherits Self::regenerate’s semantics.

Source

pub fn remove(&mut self, path: String) -> Result<()>

Remove an existing file from every design without deleting it from disk. Rejects empty designs. Inherits Self::regenerate’s semantics.

Source

pub async fn add_async( self, path: String, name: Option<String>, variant: Option<String>, ) -> Result<Self, RegenerateError>

Consuming async equivalent of Self::add, with Self::regenerate_async’s recovery semantics.

Source

pub async fn update_async( self, path: String, name: Option<String>, ) -> Result<Self, RegenerateError>

Consuming async equivalent of Self::update, with Self::regenerate_async’s recovery semantics.

Source

pub async fn remove_async(self, path: String) -> Result<Self, RegenerateError>

Consuming async equivalent of Self::remove, with Self::regenerate_async’s recovery semantics.

Source

pub async fn add_snapshot_async( &self, path: String, name: Option<String>, variant: Option<String>, ) -> Result<Self>

Snapshot-preserving async addition for adapters; inherits Self::regenerate_snapshot_async’s lineage and cancellation rules.

Source

pub async fn update_snapshot_async( &self, path: String, name: Option<String>, ) -> Result<Self>

Snapshot-preserving async update for adapters; inherits Self::regenerate_snapshot_async’s lineage and cancellation rules.

Source

pub async fn remove_snapshot_async(&self, path: String) -> Result<Self>

Snapshot-preserving async removal for adapters; inherits Self::regenerate_snapshot_async’s lineage and cancellation rules.

Source§

impl GenerateWebfontsResult

Source

pub fn regenerate( &mut self, files: &RegenerationFiles, changes: &[(String, GlyphChange)], ) -> Result<()>

Rebuild after a batch of file changes, reusing cached glyph geometry for files whose contents are unchanged. Requires the result to have been generated with incremental enabled. files selects the matching ordinary or variant input mode. Each contained list is the complete file set after the changes, in the order a fresh build would use (e.g. the glob result); the rebuilt glyphs are ordered to match it, so auto-assigned codepoints and glyph order — and therefore the output bytes — are identical to a fresh generate of that set, including for additions that sort before existing glyphs. changes describes what to do per affected file: added/changed files are read from disk and re-parsed; any file absent from its list is dropped (an explicit Removed is optional but harmless). Every requested format is rebuilt in memory, and — matching generate — when the result was built with write_files enabled the refreshed fonts are written to disk too, while CSS/HTML companion files are skipped if their rendered bytes are unchanged from the previous write. Rendered CSS/HTML is reused when the glyph names and codepoints the templates read are unchanged (a content edit), and re-rendered otherwise.

For families, supply every configured variant exactly once. Each design’s file order is independent. Hints describe family-wide paths: Added is new to the family, Changed applies to every final consumer, and Removed must be absent from every final list. Membership-only changes need no hint; newly assigned paths are loaded automatically. Invalid batches and font-build failures preserve the previous result. Variant writes occur after the new state commits, so write errors leave retryable new in-memory output.

use webfont_generator::{
    generate_sync, FontType, GenerateWebfontsOptions, GlyphChange,
};

let files = vec![
    "icons/add.svg".to_owned(),
    "icons/remove.svg".to_owned(),
];
let mut result = generate_sync(
    GenerateWebfontsOptions {
        dest: "dist".to_owned(),
        files: files.clone(),
        incremental: Some(true),
        types: Some(vec![FontType::Woff2]),
        write_files: Some(false),
        ..Default::default()
    },
    None,
)?;

result.regenerate(
    &webfont_generator::RegenerationFiles::Single(files),
    &[(
        "icons/add.svg".to_owned(),
        GlyphChange::Changed { name: None },
    )],
)?;
Source

pub async fn regenerate_async( self, files: RegenerationFiles, changes: Vec<(String, GlyphChange)>, ) -> Result<Self, RegenerateError>

Asynchronously rebuild on Tokio’s blocking pool and return the next result generation. This consumes self, so Rust prevents reuse of a stale result after success. On ordinary failure, RegenerateError::into_result returns the input result for retry. This future is not cancellation-safe: dropping it lets already-started blocking work finish and drops the consumed result; filesystem writes may continue.

use webfont_generator::{generate_sync, GenerateWebfontsOptions, GlyphChange};

let files = vec!["icons/add.svg".to_owned()];
let result = generate_sync(GenerateWebfontsOptions {
    files: files.clone(),
    dest: "dist".to_owned(),
    incremental: Some(true),
    ..Default::default()
}, None)?;
let result = result.regenerate_async(
    webfont_generator::RegenerationFiles::Single(files.clone()),
    vec![(files[0].clone(), GlyphChange::Changed { name: None })],
).await?;
Source

pub fn regenerate_all(&mut self, files: &RegenerationFiles) -> Result<()>

Rebuild after re-diffing the complete ordered file set against the retained incremental cache. This is useful when the caller has a fresh file list but not a reliable watcher change batch: every current path is re-read and hashed, missing prior paths are treated as removed, new paths as added, and paths whose content hash changed as changed. Existing glyph names are preserved; added paths derive their glyph name from the file stem.

use webfont_generator::{generate_sync, GenerateWebfontsOptions};

let files = vec!["icons/add.svg".to_owned()];
let mut result = generate_sync(GenerateWebfontsOptions {
    files: files.clone(),
    dest: "dist".to_owned(),
    incremental: Some(true),
    ..Default::default()
}, None)?;
result.regenerate_all(&webfont_generator::RegenerationFiles::Single(files))?;
Source

pub async fn regenerate_all_async( self, files: RegenerationFiles, ) -> Result<Self, RegenerateError>

Asynchronously re-diff and rebuild on Tokio’s blocking pool, consuming the old result and returning the next result generation. This future is not cancellation-safe: dropping it lets already-started blocking work finish and drops the consumed result.

use webfont_generator::{generate_sync, GenerateWebfontsOptions};

let files = vec!["icons/add.svg".to_owned()];
let result = generate_sync(GenerateWebfontsOptions {
    files: files.clone(),
    dest: "dist".to_owned(),
    incremental: Some(true),
    ..Default::default()
}, None)?;
let result = result.regenerate_all_async(webfont_generator::RegenerationFiles::Single(files)).await?;
Source§

impl GenerateWebfontsResult

Source

pub fn generate_ts(&self) -> Result<Arc<String>>

Render a fixed TypeScript source module with icons, IconName, iconBaseSelector, and iconClassPrefix. Repeated calls share the output. Uses effective CSS context settings, independent of CSS/HTML templates or output flags.

Source

pub fn generate_css_pure( &self, urls: Option<HashMap<FontType, String>>, ) -> Result<String>

Generate a CSS string for this webfont result.

Pass urls to override the default font URLs in the CSS output.

Source

pub fn generate_html_pure( &self, urls: Option<HashMap<FontType, String>>, ) -> Result<String>

Generate an HTML string for this webfont result.

Pass urls to override the default font URLs in the HTML output.

Source§

impl GenerateWebfontsResult

Source

pub async fn regenerate_snapshot_async( &self, files: RegenerationFiles, changes: Option<Vec<(String, GlyphChange)>>, ) -> Result<Self>

Rebuild on Tokio’s blocking pool, preserving this result as a readable snapshot.

Returns a replacement result on success. This result remains readable, but can no longer regenerate after it has been replaced. Concurrent regeneration attempts on the same result are rejected. On failure, its regeneration state is restored for retry, including reconciliation of any partially completed variant output writes.

Pass Some(changes) to supply explicit changes, or None to infer them from the complete input membership. Requires generation with incremental: true.

Unlike Self::regenerate_async, this method borrows rather than consumes the receiver. Prefer the consuming API when Rust ownership can enforce replacement. This future is not cancellation-safe: dropping it does not stop blocking work or filesystem writes. If that work succeeds, this receiver remains replaced even though the new result can no longer be retrieved from the dropped future.

Source§

impl GenerateWebfontsResult

Source

pub fn eot_bytes(&self) -> Option<&[u8]>

Returns the EOT font bytes, if generated.

Source

pub fn svg_string(&self) -> Option<&str>

Returns the SVG font string, if generated.

Source

pub fn ttf_bytes(&self) -> Option<&[u8]>

Returns the TTF font bytes, if generated.

Source

pub fn woff_bytes(&self) -> Option<&[u8]>

Returns the WOFF font bytes, if generated.

Source

pub fn woff2_bytes(&self) -> Option<&[u8]>

Returns the WOFF2 font bytes, if generated.

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> ErasedDestructor for T
where T: 'static,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool