pub struct DomStringMap<'a, Ext: 'static> { /* private fields */ }Expand description
Read-side view of el.dataset. Borrows the element via
NodeRef; lookup converts a camelCase key to a data-*
attribute name on the fly.
Implementations§
Source§impl<'a, Ext: 'static> DomStringMap<'a, Ext>
impl<'a, Ext: 'static> DomStringMap<'a, Ext>
Sourcepub fn new(node: NodeRef<'a, Ext>) -> Self
pub fn new(node: NodeRef<'a, Ext>) -> Self
Construct from a borrowed NodeRef. Used by the
NodeRef::dataset() integration (M4b step 19) and tests.
Sourcepub fn get(&self, key: &str) -> Option<&'a str>
pub fn get(&self, key: &str) -> Option<&'a str>
Read the data-* attribute corresponding to key. Returns
None when no such attribute is set. DOM
el.dataset[key].
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
true iff a data-* attribute corresponding to key
exists on the element. DOM key in el.dataset.
Sourcepub fn iter(&self) -> impl Iterator<Item = (String, &'a str)> + 'a
pub fn iter(&self) -> impl Iterator<Item = (String, &'a str)> + 'a
Iterate (key, value) pairs over every data-* attribute
that round-trips through the camelCase ↔ kebab-case rule.
Attributes like data-Foo (uppercase) or data- (empty
key) are skipped because they aren’t valid HTML data
attributes and don’t have a JS-side key.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Count of valid data-* attributes (entries that would
appear in Self::iter).