add an iterator over all events

This iterator returns tuples conntaining the event name and whatever the
value is.
This commit is contained in:
Matthew Nicholson 2019-03-31 00:04:33 -04:00
parent 3edc4c3fa0
commit 559359b2ff
2 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,7 @@
use crate::OutputType;
use htmlescape::encode_attribute;
use std::fmt::{Display, Error, Formatter};
use std::iter;
/// Trait for event handlers.
pub trait EventHandler<T: OutputType, E> {
@ -37,6 +38,18 @@ macro_rules! declare_events_struct {
)*
}
impl<T> Events<T> {
pub fn iter(&self) -> impl Iterator<Item = (&'static str, &T)> {
iter::empty()
$(
.chain(
self.$name.iter()
.map(|value| (stringify!($name), value))
)
)*
}
}
impl<T> Default for Events<T> {
fn default() -> Self {
Events {

View File

@ -1,3 +1,4 @@
#![recursion_limit = "128"]
//! This crate provides the `html!` macro for building HTML documents inside your
//! Rust code using roughly [JSX] compatible syntax.
//!