[−][src]Struct dodrio::Cached
A renderable that supports caching for when rendering is expensive but can generate the same DOM tree.
Example
The TodoMVC example caches individual todo items.
Implementations
impl<R> Cached<R> where
R: Default,
[src]
R: Default,
pub fn new(inner: R) -> Cached<R>
[src]
Construct a new Cached<R>
of an inner R
.
Example
use dodrio::{Cached, Node, Render, RenderContext}; #[derive(Default)] pub struct Counter { count: u32, } impl<'a> Render<'a> for Counter { fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a> { // ... } } // Create a render-able counter. let counter = Counter { count: 0 }; // And cache its rendering! let cached_counter = Cached::new(counter);
pub fn invalidate(cached: &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 will keep
displaying greetings to old who
s.
use dodrio::{bumpalo, Cached, Node, Render, RenderContext}; /// A component that renders to "<p>Hello, {who}!</p>" #[derive(Default)] pub struct Hello { who: String } impl<'a> Render<'a> for Hello { fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a> { use dodrio::builder::*; let greeting = bumpalo::format!(in cx.bump, "Hello, {}!", self.who); p(&cx) .children([text(greeting.into_bump_str())]) .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: Self) -> R
[src]
Convert a Cached<R>
back into a plain R
.
Trait Implementations
impl<R: Clone> Clone for Cached<R> where
R: Default,
[src]
R: Default,
impl<R: Debug> Debug for Cached<R> where
R: Default,
[src]
R: Default,
impl<R: Default> Default for Cached<R> where
R: Default,
[src]
R: Default,
impl<R> Deref for Cached<R> where
R: Default,
[src]
R: Default,
impl<R> DerefMut for Cached<R> where
R: Default,
[src]
R: Default,
impl<'a, R> Render<'a> for Cached<R> where
R: 'static + Default + for<'b> Render<'b>,
[src]
R: 'static + Default + for<'b> Render<'b>,
fn render(&self, cx: &mut RenderContext<'a>) -> Node<'a>
[src]
Auto Trait Implementations
impl<R> !RefUnwindSafe for Cached<R>
impl<R> Send for Cached<R> where
R: Send,
R: Send,
impl<R> !Sync for Cached<R>
impl<R> Unpin for Cached<R> where
R: Unpin,
R: Unpin,
impl<R> UnwindSafe for Cached<R> where
R: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> 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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,