on master help sign in
Deny missing docs and missing `Debug` implementations
197915dNick Fitzgerald
src/cached.rs+1
@@ -13,6 +13,7 @@ use std::ops::{Deref, DerefMut};
13
13
14/// A renderable that supports caching for when rendering is expensive but can
14/// A renderable that supports caching for when rendering is expensive but can
15/// generate the same DOM tree.
15/// generate the same DOM tree.
16+#[derive(Debug)]
16pub struct Cached<R> {
17pub struct Cached<R> {
17 inner: R,
18 inner: R,
18 bump: bumpalo::Bump,
19 bump: bumpalo::Bump,
src/change_list.rs+2−1
@@ -100,7 +100,8 @@ impl ChangeList {
100}
100}
101
101
102#[repr(u32)]
102#[repr(u32)]
103+#[derive(Clone, Copy, Debug)]
103−pub enum ChangeDiscriminant {
104+enum ChangeDiscriminant {
104 /// Immediates: `(pointer, length)`
105 /// Immediates: `(pointer, length)`
105 ///
106 ///
106 /// Stack: `[... TextNode] -> [... TextNode]`
107 /// Stack: `[... TextNode] -> [... TextNode]`
src/lib.rs+1
@@ -54,6 +54,7 @@
54//! }
54//! }
55//! }
55//! }
56//! ```
56//! ```
57+#![deny(missing_docs, missing_debug_implementations)]
57
58
58// Re-export the `bumpalo` crate.
59// Re-export the `bumpalo` crate.
59pub use bumpalo;
60pub use bumpalo;
src/node.rs+4
@@ -48,9 +48,13 @@ pub struct Listener<'a> {
48 pub callback: ListenerCallback<'a>,
48 pub callback: ListenerCallback<'a>,
49}
49}
50
50
51+/// An attribute on a DOM node, such as `id="my-thing"` or
52+/// `href="https://example.com"`.
51#[derive(Clone, Debug)]
53#[derive(Clone, Debug)]
52pub struct Attribute<'a> {
54pub struct Attribute<'a> {
55+ /// The attribute name, such as `id`.
53 pub name: &'a str,
56 pub name: &'a str,
57+ /// The attribute value, such as `"my-thing"`.
54 pub value: &'a str,
58 pub value: &'a str,
55}
59}
56
60
src/render.rs+38
@@ -4,7 +4,45 @@ use std::any::Any;
4use std::rc::Rc;
4use std::rc::Rc;
5use wasm_bindgen::UnwrapThrowExt;
5use wasm_bindgen::UnwrapThrowExt;
6
6
7+/// A trait for any component that can be rendered to HTML.
8+///
9+/// Takes a shared reference to `self` and generates the virtual DOM that
10+/// represents its rendered HTML.
11+///
12+/// ## `Bump` Allocation
13+///
14+/// `Render` implementations can use the provided `Bump` for very fast
15+/// allocation for anything that needs to be allocated during rendering.
16+///
17+/// ## The `'a: 'bump` Lifetime Bound
18+///
19+/// The `'a: 'bump` bounds enforce that `self` outlives the given bump
20+/// allocator. This means that if `self` contains a string, the string does not
21+/// need to be copied into the output `Node` and can be used by reference
22+/// instead (i.e. it prevents accidentally using the string after its been
23+/// freed). The `'a: 'bump` bound also enables abstractions like
24+/// `dodrio::Cached` that can re-use cached `Node`s across `render`s without
25+/// copying them.
26+///
27+/// ## Example
28+///
29+/// ```no_run
30+/// use dodrio::{Bump, Node, Render};
31+///
32+/// pub struct MyComponent;
33+///
34+/// impl Render for MyComponent {
35+/// fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
36+/// where
37+/// 'a: 'bump
38+/// {
39+/// Node::text("This is my component rendered!")
40+/// }
41+/// }
42+/// ```
7pub trait Render {
43pub trait Render {
44+ /// Render `self` as a virtual DOM. Use the given `Bump` for temporary
45+ /// allocations.
8 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
46 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
9 where
47 where
10 'a: 'bump;
48 'a: 'bump;
src/vdom.rs+1
@@ -22,6 +22,7 @@ use wasm_bindgen_futures::JsFuture;
22/// removed. To keep it mounted forever, use the `Vdom::forget` method.
22/// removed. To keep it mounted forever, use the `Vdom::forget` method.
23#[must_use = "A `Vdom` will only keep rendering and listening to events while it has not been \
23#[must_use = "A `Vdom` will only keep rendering and listening to events while it has not been \
24 dropped. If you want a `Vdom` to run forever, call `Vdom::forget`."]
24 dropped. If you want a `Vdom` to run forever, call `Vdom::forget`."]
25+#[derive(Debug)]
25pub struct Vdom {
26pub struct Vdom {
26 inner: Rc<VdomInner>,
27 inner: Rc<VdomInner>,
27}
28}