Skip to main content

afia_component/dom/
node_list.rs

1//! Types related to `NodeList`s.
2//!
3//! ## MDN Documentation
4//! https://developer.mozilla.org/en-US/docs/Web/API/NodeList
5
6use crate::dom::node::DomNode;
7use crate::ComponentImports;
8
9/// A `NodeList`.
10///
11/// ## MDN Documentation
12/// https://developer.mozilla.org/en-US/docs/Web/API/NodeList
13#[derive(Clone)]
14pub struct NodeList {
15    handle: i64,
16    imports: ComponentImports,
17}
18
19impl NodeList {
20    pub(crate) fn new(handle: i64, imports: ComponentImports) -> Self {
21        Self { handle, imports }
22    }
23
24    /// Get the node at the given index within the list.
25    pub fn item(&self, index: i32) -> Option<DomNode> {
26        let item = unsafe {
27            afia_component_sys::node_list_item(
28                self.imports.component_imports_ptr,
29                self.handle,
30                index,
31            )
32        };
33        DomNode::new_maybe(&self.imports, item)
34    }
35}