on master help sign in
Deny missing docs and missing `Debug` implementations
commit197915dff19794bd85a11c8f8de620beb26d9d5e authorNick Fitzgerald <fitzgen@gmail.com> dateSun 10 Feb 2019, 16:17 (8 years ago) parentdaa23fe
6 files changed+47−1
src/cached.rs+1 src/change_list.rs+2−1 src/lib.rs+1 src/node.rs+4 src/render.rs+38 src/vdom.rs+1
src/cached.rs+1
@@ -13,6 +13,7 @@ use std::ops::{Deref, DerefMut};
1313
1414/// A renderable that supports caching for when rendering is expensive but can
1515/// generate the same DOM tree.
16+#[derive(Debug)]
1617pub struct Cached<R> {
1718 inner: R,
1819 bump: bumpalo::Bump,
src/change_list.rs+2−1
@@ -100,7 +100,8 @@ impl ChangeList {
100100}
101101
102102#[repr(u32)]
103−pub enum ChangeDiscriminant {
103+#[derive(Clone, Copy, Debug)]
104+enum ChangeDiscriminant {
104105 /// Immediates: `(pointer, length)`
105106 ///
106107 /// Stack: `[... TextNode] -> [... TextNode]`
src/lib.rs+1
@@ -54,6 +54,7 @@
5454//! }
5555//! }
5656//! ```
57+#![deny(missing_docs, missing_debug_implementations)]
5758
5859// Re-export the `bumpalo` crate.
5960pub use bumpalo;
src/node.rs+4
@@ -48,9 +48,13 @@ pub struct Listener<'a> {
4848 pub callback: ListenerCallback<'a>,
4949}
5050
51+/// An attribute on a DOM node, such as `id="my-thing"` or
52+/// `href="https://example.com"`.
5153#[derive(Clone, Debug)]
5254pub struct Attribute<'a> {
55+ /// The attribute name, such as `id`.
5356 pub name: &'a str,
57+ /// The attribute value, such as `"my-thing"`.
5458 pub value: &'a str,
5559}
5660
src/render.rs+38
@@ -4,7 +4,45 @@ use std::any::Any;
44use std::rc::Rc;
55use wasm_bindgen::UnwrapThrowExt;
66
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+/// ```
743pub trait Render {
44+ /// Render `self` as a virtual DOM. Use the given `Bump` for temporary
45+ /// allocations.
846 fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
947 where
1048 'a: 'bump;
src/vdom.rs+1
@@ -22,6 +22,7 @@ use wasm_bindgen_futures::JsFuture;
2222/// removed. To keep it mounted forever, use the `Vdom::forget` method.
2323#[must_use = "A `Vdom` will only keep rendering and listening to events while it has not been \
2424 dropped. If you want a `Vdom` to run forever, call `Vdom::forget`."]
25+#[derive(Debug)]
2526pub struct Vdom {
2627 inner: Rc<VdomInner>,
2728}