Add Send bound. Fixes #50
This commit is contained in:
parent
1588f30353
commit
62dd064f79
|
@ -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
|
||||
|
@ -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()
|
||||
$(
|
||||
|
@ -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>>;
|
||||
|
||||
|
@ -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 {
|
||||
$(
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>>,
|
||||
)*
|
||||
}
|
||||
|
||||
|
@ -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))
|
||||
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue