pub struct MdCache { /* private fields */ }Expand description
A bounded memo of source text → rendered El for one
MarkdownOptions configuration.
ⓘ
struct ChatApp {
md_cache: RefCell<MdCache>, // interior-mutable: written during build
// …
}
// per visible message, every frame:
let rendered = self.md_cache.borrow_mut().get(&message.text);Keys are the full source text (no hash-collision risk); values are
El subtrees cloned out on hit. A streaming message changes text
each delta, so it naturally misses (re-parses) while growing and
starts hitting once stable; superseded partial entries age out via
LRU.
Implementations§
Source§impl MdCache
impl MdCache
Sourcepub fn new(options: MarkdownOptions) -> Self
pub fn new(options: MarkdownOptions) -> Self
A cache rendering with options, holding up to
[DEFAULT_CAPACITY] entries.
Sourcepub fn with_capacity(options: MarkdownOptions, capacity: usize) -> Self
pub fn with_capacity(options: MarkdownOptions, capacity: usize) -> Self
A cache with an explicit entry cap. Size it to your visible window plus scroll-back margin; each entry holds the source text and the rendered subtree.
Sourcepub fn get(&mut self, text: &str) -> El
pub fn get(&mut self, text: &str) -> El
The rendered tree for text — a clone of the cached subtree on
hit, a fresh parse (then cached) on miss.
Auto Trait Implementations§
impl !RefUnwindSafe for MdCache
impl !UnwindSafe for MdCache
impl Freeze for MdCache
impl Send for MdCache
impl Sync for MdCache
impl Unpin for MdCache
impl UnsafeUnpin for MdCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.