@@ -68,24 +68,44 @@ pub_unstable_internal! {
71−pub_unstable_internal! {
72− /// The key for keyed children.
71+/// The key for keyed children.
73+/// Keys must be unique among siblings.
75+/// If any sibling is keyed, then they all must be keyed.
73− #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
76+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
74− pub(crate) struct NodeKey(pub(crate) u32);
77+pub struct NodeKey(pub(crate) u32);
79+impl Default for NodeKey {
80+ fn default() -> NodeKey {
77impl NodeKey {
85impl NodeKey {
86+ /// The default, lack of a key.
78 pub const NONE: NodeKey = NodeKey(u32::MAX);
87 pub const NONE: NodeKey = NodeKey(u32::MAX);
89+ /// Is this key `NodeKey::NONE`?
81 pub fn is_none(&self) -> bool {
91 pub fn is_none(&self) -> bool {
82 *self == Self::NONE
92 *self == Self::NONE
95+ /// Is this key not `NodeKey::NONE`?
86 pub fn is_some(&self) -> bool {
97 pub fn is_some(&self) -> bool {
87 !self.is_none()
98 !self.is_none()
101+ /// Create a new `NodeKey`.
103+ /// `key` must not be `u32::MAX`.
105+ pub fn new(key: u32) -> Self {
106+ debug_assert_ne!(key, u32::MAX);
91/// An event listener callback function.
111/// An event listener callback function.
@@ -162,31 +182,22 @@ impl<'a> Attribute<'a> {
164impl<'a> Node<'a> {
184impl<'a> Node<'a> {
165− /// Construct a new Node of type element with given tag name and children
185+ /// Low-level constructor for making a new `Node` of type element with given
188+ /// This is primarily intended for JSX and templating proc-macros to compile
189+ /// down into. If you are building nodes by-hand, prefer using the
190+ /// `dodrio::builder::*` APIs.
166 #[inline]
191 #[inline]
167− pub(crate) fn element<Listeners, Attributes, Children>(
192+ pub fn element(
168 bump: &'a Bump,
193 bump: &'a Bump,
169 key: NodeKey,
194 key: NodeKey,
170 tag_name: &'a str,
195 tag_name: &'a str,
171− listeners: Listeners,
196+ listeners: &'a [Listener<'a>],
172− attributes: Attributes,
197+ attributes: &'a [Attribute<'a>],
173− children: Children,
198+ children: &'a [Node<'a>],
174 namespace: Option<&'a str>,
199 namespace: Option<&'a str>,
175− ) -> Node<'a>
200+ ) -> Node<'a> {
177− Listeners: 'a + AsRef<[Listener<'a>]>,
178− Attributes: 'a + AsRef<[Attribute<'a>]>,
179− Children: 'a + AsRef<[Node<'a>]>,
181− let children: &'a Children = bump.alloc(children);
182− let children: &'a [Node<'a>] = children.as_ref();
184− let listeners: &'a Listeners = bump.alloc(listeners);
185− let listeners: &'a [Listener<'a>] = listeners.as_ref();
187− let attributes: &'a Attributes = bump.alloc(attributes);
188− let attributes: &'a [Attribute<'a>] = attributes.as_ref();
190 let element = bump.alloc_with(|| ElementNode {
201 let element = bump.alloc_with(|| ElementNode {
192 tag_name,
203 tag_name,