Skip to main content

TextShapingCache

Struct TextShapingCache 

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

Bounded DPI-independent single-probe FxHash text shaping and line-break cache with O(1) intrusive LRU eviction.

Implementations§

Source§

impl TextShapingCache

Single-probe FxHash shaping & line-break caching, independent font-chain invalidation, and O(1) intrusive LRU eviction for TextShapingCache.

Source

pub fn with_budget(budget_bytes: usize) -> Self

Creates a zero-allocation empty TextShapingCache enforcing budget_bytes across shaping runs and wrapped line layouts.

§Arguments
  • usize - Resident byte ceiling (clamped to >= TEXT_SHAPING_MIN_BUDGET_BYTES).
§Returns
  • Self - Configured empty shaping cache.
Source

pub fn set_memory_budget(&mut self, max_bytes: usize)

Updates the resident byte budget and immediately evicts cold entries if currently over budget.

§Arguments
  • &Self - Mutable shaping cache.
  • usize - New maximum resident bytes.
Source

pub fn invalidate_font_chain(&mut self, new_revision: u64) -> bool

Advances the font fallback chain revision and invalidates all cached shaping and line-break entries.

§Arguments
  • &Self - Mutable shaping cache.
  • u64 - New monotonic font fallback chain revision.
§Returns
  • bool - true if the revision changed and entries were invalidated.
Source

pub fn peek_shaped(&self, key: &TextShapingKey) -> Option<&ShapedGlyphRun>

Performs a read-only single-probe zero-mutation lookup of a cached ShapedGlyphRun.

§Arguments
  • &Self - Shaping cache reference.
  • &TextShapingKey - Shaping lookup key.
§Returns
  • Option<&ShapedGlyphRun> - Cached shaping run when resident.
Source

pub fn peek_line_break(&self, key: &LineBreakKey) -> Option<&TextLayoutResult>

Performs a read-only single-probe zero-mutation lookup of a cached wrapped TextLayoutResult.

§Arguments
  • &Self - Shaping cache reference.
  • &LineBreakKey - Line-break lookup key.
§Returns
  • Option<&TextLayoutResult> - Cached wrapped layout result when resident.
Source

pub fn get_or_shape<F>( &mut self, key: TextShapingKey, shape_fn: F, ) -> &ShapedGlyphRun
where F: FnOnce() -> (Vec<f32>, f32),

Looks up or computes a DPI- and wrap-width-independent ShapedGlyphRun for key with a single FxHash probe.

§Arguments
  • &Self - Mutable shaping cache.
  • TextShapingKey - Shaping lookup key.
  • F - Lazy shaping function returning (cluster_advances, total_width) on a miss.
§Returns
  • &ShapedGlyphRun - Cached shaping run reference.
Source

pub fn get_or_break_lines<F>( &mut self, key: LineBreakKey, break_fn: F, ) -> &TextLayoutResult
where F: FnOnce() -> TextLayoutResult,

Looks up or computes a DPI- and color-independent wrapped TextLayoutResult for key with a single FxHash probe.

§Arguments
  • &Self - Mutable shaping cache.
  • LineBreakKey - Line-break lookup key.
  • F - Lazy line-break computation invoked only on cache miss.
§Returns
  • &TextLayoutResult - Cached wrapped layout result.
Source

pub fn evict_if_over_budget(&mut self)

Evicts coldest entries whenever current resident bytes exceed the configured budget.

§Arguments
  • &Self - Mutable shaping cache.
Source

pub fn total_entries(&self) -> usize

Returns total cached entry count combining shaping runs and wrapped line-break entries.

§Arguments
  • &Self - Shaping cache reference.
§Returns
  • usize - Total cached entries.
Source§

impl TextShapingCache

Source

pub fn get_budget_bytes(&self) -> usize

Source

pub fn get_mut_budget_bytes(&mut self) -> &mut usize

Source

pub fn set_budget_bytes(&mut self, val: usize) -> &mut Self

Source

pub fn get_resident_bytes(&self) -> usize

Source

pub fn get_font_chain_revision(&self) -> u64

Source

pub fn get_shaping_hits(&self) -> u64

Source

pub fn get_shaping_misses(&self) -> u64

Source

pub fn get_line_break_hits(&self) -> u64

Source

pub fn get_line_break_misses(&self) -> u64

Source

pub fn get_evictions(&self) -> u64

Trait Implementations§

Source§

impl Clone for TextShapingCache

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextShapingCache

Source§

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

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

impl Default for TextShapingCache

Default bounded text shaping cache initialized with TEXT_SHAPING_DEFAULT_BUDGET_BYTES.

Source§

fn default() -> Self

Creates an empty bounded TextShapingCache with the default 4 MiB budget.

§Returns
  • Self - Empty text shaping cache.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.