Skip to content

Commit 62dd064

Browse files
jonathanKingstonbodil
authored andcommitted
Add Send bound. Fixes bodil#50
1 parent 1588f30 commit 62dd064

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

typed-html/src/events.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::fmt::{Display, Error, Formatter};
66
use std::iter;
77

88
/// Trait for event handlers.
9-
pub trait EventHandler<T: OutputType, E> {
9+
pub trait EventHandler<T: OutputType + Send, E: Send> {
1010
/// Build a callback function from this event handler.
1111
///
1212
/// Returns `None` is this event handler can't be used to build a callback
@@ -26,13 +26,13 @@ pub trait EventHandler<T: OutputType, E> {
2626

2727
macro_rules! declare_events_struct {
2828
($($name:ident,)*) => {
29-
pub struct Events<T> {
29+
pub struct Events<T> where T: Send {
3030
$(
3131
pub $name: Option<T>,
3232
)*
3333
}
3434

35-
impl<T> Events<T> {
35+
impl<T: Send> Events<T> {
3636
pub fn iter(&self) -> impl Iterator<Item = (&'static str, &T)> {
3737
iter::empty()
3838
$(
@@ -54,7 +54,7 @@ macro_rules! declare_events_struct {
5454
}
5555
}
5656

57-
impl<T: 'static> IntoIterator for Events<T> {
57+
impl<T: 'static + Send> IntoIterator for Events<T> {
5858
type Item = (&'static str, T);
5959
type IntoIter = Box<dyn Iterator<Item = Self::Item>>;
6060

@@ -72,7 +72,7 @@ macro_rules! declare_events_struct {
7272
}
7373
}
7474

75-
impl<T> Default for Events<T> {
75+
impl<T: Send> Default for Events<T> {
7676
fn default() -> Self {
7777
Events {
7878
$(
@@ -82,7 +82,7 @@ macro_rules! declare_events_struct {
8282
}
8383
}
8484

85-
impl<T: Display> Display for Events<T> {
85+
impl<T: Display + Send> Display for Events<T> {
8686
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
8787
$(
8888
if let Some(ref value) = self.$name {

typed-html/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ pub mod types;
214214
/// Marker trait for outputs
215215
pub trait OutputType {
216216
/// The type that contains events for this output.
217-
type Events: Default + Display;
217+
type Events: Default + Display + Send;
218218
/// The type of event targets for this output.
219-
type EventTarget;
219+
type EventTarget: Send;
220220
/// The type that's returned from attaching an event listener to a target.
221-
type EventListenerHandle;
221+
type EventListenerHandle: Send;
222222
}
223223

224224
/// String output

typed-html/src/output/stdweb.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ macro_rules! declare_events {
2121
/// Container type for DOM events.
2222
pub struct Events {
2323
$(
24-
pub $name: Option<Box<dyn EventHandler<Stdweb, $type>>>,
24+
pub $name: Option<Box<dyn EventHandler<Stdweb, $type> + Send>>,
2525
)*
2626
}
2727

@@ -129,17 +129,17 @@ pub struct EFn<F, E>(Option<F>, PhantomData<E>);
129129

130130
impl<F, E> EFn<F, E>
131131
where
132-
F: FnMut(E) + 'static,
132+
F: FnMut(E) + 'static + Send,
133133
{
134134
pub fn new(f: F) -> Self {
135135
EFn(Some(f), PhantomData)
136136
}
137137
}
138138

139-
impl<F, E> From<F> for Box<dyn EventHandler<Stdweb, E>>
139+
impl<F, E> From<F> for Box<dyn EventHandler<Stdweb, E> + Send>
140140
where
141-
F: FnMut(E) + 'static,
142-
E: ConcreteEvent + 'static,
141+
F: FnMut(E) + 'static + Send,
142+
E: ConcreteEvent + 'static + Send,
143143
{
144144
fn from(f: F) -> Self {
145145
Box::new(EFn::new(f))
@@ -148,8 +148,8 @@ where
148148

149149
impl<F, E> EventHandler<Stdweb, E> for EFn<F, E>
150150
where
151-
F: FnMut(E) + 'static,
152-
E: ConcreteEvent + 'static,
151+
F: FnMut(E) + 'static + Send,
152+
E: ConcreteEvent + 'static + Send,
153153
{
154154
fn attach(&mut self, target: &mut <Stdweb as OutputType>::EventTarget) -> EventListenerHandle {
155155
let handler = self.0.take().unwrap();

0 commit comments

Comments
 (0)