Skip to main content

CachingProcessor

Struct CachingProcessor 

Source
pub struct CachingProcessor<'a> { /* private fields */ }
Expand description

A Markdown processor that caches rendered output per document.

§Example

use mdx_gen::{CachingProcessor, MarkdownOptions};

let processor = CachingProcessor::new(MarkdownOptions::default());
let first = processor.process("# Hello").unwrap();   // miss: renders
let second = processor.process("# Hello").unwrap();  // hit: cached
assert_eq!(first, second);

let stats = processor.stats();
assert_eq!((stats.hits, stats.misses), (1, 1));

Implementations§

Source§

impl<'a> CachingProcessor<'a>

Source

pub fn new(options: MarkdownOptions<'a>) -> Self

Creates a processor with DEFAULT_CAPACITY entries.

Source

pub fn with_capacity(options: MarkdownOptions<'a>, capacity: usize) -> Self

Creates a processor that keeps at most capacity documents. A capacity of 0 disables caching: every call renders.

Source

pub fn options(&self) -> &MarkdownOptions<'a>

The options every render uses.

Source

pub fn capacity(&self) -> usize

The maximum number of cached documents.

Source

pub fn len(&self) -> usize

Number of documents currently cached (both variants).

Source

pub fn is_empty(&self) -> bool

Returns true when nothing is cached.

Source

pub fn stats(&self) -> CacheStats

Hit and miss counts since creation or the last clear.

Source

pub fn clear(&self)

Drops every cached document and resets the counters.

Source

pub fn process(&self, content: &str) -> Result<String, MarkdownError>

Cached equivalent of process_markdown.

§Errors

Mirrors process_markdown. Errors are not cached.

Source

pub fn process_with_toc( &self, content: &str, ) -> Result<(String, Vec<Heading>), MarkdownError>

Cached equivalent of process_markdown_with_toc.

§Errors

Mirrors process_markdown_with_toc. Errors are not cached.

Trait Implementations§

Source§

impl Debug for CachingProcessor<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for CachingProcessor<'a>

§

impl<'a> Forget for CachingProcessor<'a>

§

impl<'a> Move for CachingProcessor<'a>

§

impl<'a> RefUnwindSafe for CachingProcessor<'a>

§

impl<'a> Send for CachingProcessor<'a>

§

impl<'a> Sync for CachingProcessor<'a>

§

impl<'a> Unpin for CachingProcessor<'a>

§

impl<'a> UnsafeUnpin for CachingProcessor<'a>

§

impl<'a> UnwindSafe for CachingProcessor<'a>

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

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

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.