pub struct ParsedSourceLru<T> { /* private fields */ }Expand description
Bounded LRU cache mapping SourceHash to Arc<T>. Eviction is
LRU by last-touched order. Hits are O(1); eviction scans the bounded live
set only when an insert needs space.
Implementations§
Source§impl<T> ParsedSourceLru<T>
impl<T> ParsedSourceLru<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Build an empty cache that holds at most capacity entries.
capacity == 0 disables caching entirely (every lookup is a
miss and nothing is stored).
Sourcepub fn get(&self, key: SourceHash) -> Option<Arc<T>>
pub fn get(&self, key: SourceHash) -> Option<Arc<T>>
Look up key. Returns the cached Arc<T> on hit (and bumps
recency); returns None on miss.
Sourcepub fn insert(&self, key: SourceHash, value: T) -> Arc<T>
pub fn insert(&self, key: SourceHash, value: T) -> Arc<T>
Insert value for key, evicting the oldest entry if the
cache is at capacity. Returns the inserted Arc<T>.
Sourcepub fn get_or_parse<F>(&self, source: &[u8], extra: &[u8], parse: F) -> Arc<T>
pub fn get_or_parse<F>(&self, source: &[u8], extra: &[u8], parse: F) -> Arc<T>
Look up key; on miss, run parse(source) to produce the
value and insert it. Returns the cached or freshly inserted
Arc<T>.
Auto Trait Implementations§
impl<T> !Freeze for ParsedSourceLru<T>
impl<T> RefUnwindSafe for ParsedSourceLru<T>
impl<T> Send for ParsedSourceLru<T>
impl<T> Sync for ParsedSourceLru<T>
impl<T> Unpin for ParsedSourceLru<T>
impl<T> UnsafeUnpin for ParsedSourceLru<T>
impl<T> UnwindSafe for ParsedSourceLru<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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