Skip to main content

CompileCache

Struct CompileCache 

Source
pub struct CompileCache<K, V> { /* private fields */ }
Expand description

A compile cache created from one immutable key.

Compilation inputs live in the key, so changing one produces a new, empty cache through CompileCache::map_key; nothing is ever cleared by hand. Clones share their results. A variant distinguishes environments that are not part of the key, such as the font snapshot a paragraph is shaped with.

Implementations§

Source§

impl<K, V: Clone> CompileCache<K, V>

Source

pub fn new(key: K) -> Self

Creates an empty cache for a key.

Source

pub fn key(&self) -> &K

The immutable key every cached result was compiled from.

Source

pub fn shares(&self, other: &Self) -> bool

Whether two caches share their results, as clones and unchanged keys do.

Source

pub fn is_compiled(&self) -> bool

Whether any result has been compiled yet.

Source

pub fn get_or_compile(&self, variant: u64, compile: impl FnOnce(&K) -> V) -> V

Returns the result for a variant, compiling it once from the key. The compiler runs while the cache is locked, so concurrent callers never compile the same variant twice.

Source§

impl<K: Clone + PartialEq, V: Clone> CompileCache<K, V>

Source

pub fn map_key(&self, change: impl FnOnce(&mut K)) -> Self

Applies a change to a copy of the key. An unchanged key keeps sharing this cache; a changed key gets a new one.

Trait Implementations§

Source§

impl<K, V> Clone for CompileCache<K, V>

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<K: Debug, V> Debug for CompileCache<K, V>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> Forget for CompileCache<K, V>

§

impl<K, V> Freeze for CompileCache<K, V>
where Arc<K>: Freeze, Arc<Mutex<BTreeMap<u64, V>>>: Freeze,

§

impl<K, V> Move for CompileCache<K, V>

§

impl<K, V> RefUnwindSafe for CompileCache<K, V>

§

impl<K, V> Send for CompileCache<K, V>
where Arc<K>: Send, Arc<Mutex<BTreeMap<u64, V>>>: Send,

§

impl<K, V> Sync for CompileCache<K, V>
where Arc<K>: Sync, Arc<Mutex<BTreeMap<u64, V>>>: Sync,

§

impl<K, V> Unpin for CompileCache<K, V>
where Arc<K>: Unpin, Arc<Mutex<BTreeMap<u64, V>>>: Unpin,

§

impl<K, V> UnsafeUnpin for CompileCache<K, V>

§

impl<K, V> UnwindSafe for CompileCache<K, V>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.