Skip to content

Commit

Permalink
Add Send bound. Fixes #50
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston authored and bodil committed May 28, 2019
1 parent 1588f30 commit 62dd064
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions typed-html/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt::{Display, Error, Formatter};
use std::iter;

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

macro_rules! declare_events_struct {
($($name:ident,)*) => {
pub struct Events<T> {
pub struct Events<T> where T: Send {
$(
pub $name: Option<T>,
)*
}

impl<T> Events<T> {
impl<T: Send> Events<T> {
pub fn iter(&self) -> impl Iterator<Item = (&'static str, &T)> {
iter::empty()
$(
Expand All @@ -54,7 +54,7 @@ macro_rules! declare_events_struct {
}
}

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

Expand All @@ -72,7 +72,7 @@ macro_rules! declare_events_struct {
}
}

impl<T> Default for Events<T> {
impl<T: Send> Default for Events<T> {
fn default() -> Self {
Events {
$(
Expand All @@ -82,7 +82,7 @@ macro_rules! declare_events_struct {
}
}

impl<T: Display> Display for Events<T> {
impl<T: Display + Send> Display for Events<T> {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
$(
if let Some(ref value) = self.$name {
Expand Down
6 changes: 3 additions & 3 deletions typed-html/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ pub mod types;
/// Marker trait for outputs
pub trait OutputType {
/// The type that contains events for this output.
type Events: Default + Display;
type Events: Default + Display + Send;
/// The type of event targets for this output.
type EventTarget;
type EventTarget: Send;
/// The type that's returned from attaching an event listener to a target.
type EventListenerHandle;
type EventListenerHandle: Send;
}

/// String output
Expand Down
14 changes: 7 additions & 7 deletions typed-html/src/output/stdweb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ macro_rules! declare_events {
/// Container type for DOM events.
pub struct Events {
$(
pub $name: Option<Box<dyn EventHandler<Stdweb, $type>>>,
pub $name: Option<Box<dyn EventHandler<Stdweb, $type> + Send>>,
)*
}

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

impl<F, E> EFn<F, E>
where
F: FnMut(E) + 'static,
F: FnMut(E) + 'static + Send,
{
pub fn new(f: F) -> Self {
EFn(Some(f), PhantomData)
}
}

impl<F, E> From<F> for Box<dyn EventHandler<Stdweb, E>>
impl<F, E> From<F> for Box<dyn EventHandler<Stdweb, E> + Send>
where
F: FnMut(E) + 'static,
E: ConcreteEvent + 'static,
F: FnMut(E) + 'static + Send,
E: ConcreteEvent + 'static + Send,
{
fn from(f: F) -> Self {
Box::new(EFn::new(f))
Expand All @@ -148,8 +148,8 @@ where

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

0 comments on commit 62dd064

Please sign in to comment.