[−][src]Struct dodrio::Cached
A renderable that supports caching for when rendering is expensive but can generate the same DOM tree.
Methods
impl<R> Cached<R>
[src]
pub fn new(inner: R) -> Cached<R>
[src]
Construct a new Cached<R>
of an inner R
.
Example
use bumpalo::Bump; use dodrio::{Cached, Node, Render}; pub struct Counter { count: u32, } impl Render for Counter { fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump> where 'a: 'bump { // ... } } // Create a render-able counter. let counter = Counter { count: 0 }; // And cache its rendering! let cached_counter = Cached::new(counter);
pub fn invalidate(cached: &mut Self)
[src]
Invalidate the cached rendering.
This method should be called whenever the inner R
must be re-rendered,
and the cached Node
from the last time R::render
was invoked can no
longer be re-used.
Example
The Cached<Hello>
component must have its cache invalidated whenever
the who
string is changed, or else the cached rendering whill keep
displaying greetings to old who
s.
use bumpalo::Bump; use dodrio::{Cached, Node, Render}; /// A component that renders to "<p>Hello, {who}!</p>" pub struct Hello { who: String } impl Render for Hello { fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump> where 'a: 'bump, { use dodrio::builder::*; p(bump) .children([text("Hello, "), text(&self.who), text("!")]) .finish() } } /// Whenever a `Cached<Hello>`'s `who` is updated, we need to invalidate the /// cache so that we don't keep displaying greetings to old `who`s. pub fn set_who(hello: &mut Cached<Hello>, who: String) { hello.who = who; Cached::invalidate(hello); }
pub fn into_inner(cached: Cached<R>) -> R
[src]
Convert a Cached<R>
back into a plain R
.
Trait Implementations
impl<R: Render> Render for Cached<R>
[src]
impl<R> DerefMut for Cached<R>
[src]
impl<R: Debug> Debug for Cached<R>
[src]
impl<R> Deref for Cached<R>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,