add an iterator over all events
This iterator returns tuples conntaining the event name and whatever the value is.
This commit is contained in:
parent
3edc4c3fa0
commit
559359b2ff
|
@ -3,6 +3,7 @@
|
||||||
use crate::OutputType;
|
use crate::OutputType;
|
||||||
use htmlescape::encode_attribute;
|
use htmlescape::encode_attribute;
|
||||||
use std::fmt::{Display, Error, Formatter};
|
use std::fmt::{Display, Error, Formatter};
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
/// Trait for event handlers.
|
/// Trait for event handlers.
|
||||||
pub trait EventHandler<T: OutputType, E> {
|
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> {
|
impl<T> Default for Events<T> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Events {
|
Events {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#![recursion_limit = "128"]
|
||||||
//! This crate provides the `html!` macro for building HTML documents inside your
|
//! This crate provides the `html!` macro for building HTML documents inside your
|
||||||
//! Rust code using roughly [JSX] compatible syntax.
|
//! Rust code using roughly [JSX] compatible syntax.
|
||||||
//!
|
//!
|
||||||
|
|
Loading…
Reference in New Issue