Do not require T: Clone for EventLoopProxy<T>: Clone (#1086)

* Do not require `T: Clone` for `EventLoopProxy<T>: Clone`

* Update `CHANGELOG.md`

* Remove the conflicting `Clone` impl

* Fix match statement
This commit is contained in:
YVT 2019-08-06 05:51:42 +09:00 committed by Osspial
parent 8a1c5277eb
commit 73cf10e4f3
7 changed files with 49 additions and 6 deletions

View file

@ -479,12 +479,20 @@ pub enum EventLoop<T: 'static> {
X(x11::EventLoop<T>),
}
#[derive(Clone)]
pub enum EventLoopProxy<T: 'static> {
X(x11::EventLoopProxy<T>),
Wayland(wayland::EventLoopProxy<T>),
}
impl<T: 'static> Clone for EventLoopProxy<T> {
fn clone(&self) -> Self {
match self {
EventLoopProxy::X(proxy) => EventLoopProxy::X(proxy.clone()),
EventLoopProxy::Wayland(proxy) => EventLoopProxy::Wayland(proxy.clone()),
}
}
}
impl<T: 'static> EventLoop<T> {
pub fn new() -> EventLoop<T> {
if let Ok(env_var) = env::var(BACKEND_PREFERENCE_ENV_VAR) {

View file

@ -90,7 +90,6 @@ pub struct EventLoop<T: 'static> {
// A handle that can be sent across threads and used to wake up the `EventLoop`.
//
// We should only try and wake up the `EventLoop` if it still exists, so we hold Weak ptrs.
#[derive(Clone)]
pub struct EventLoopProxy<T: 'static> {
user_sender: ::calloop::channel::Sender<T>,
}
@ -111,6 +110,14 @@ pub struct EventLoopWindowTarget<T> {
_marker: ::std::marker::PhantomData<T>,
}
impl<T: 'static> Clone for EventLoopProxy<T> {
fn clone(&self) -> Self {
EventLoopProxy {
user_sender: self.user_sender.clone(),
}
}
}
impl<T: 'static> EventLoopProxy<T> {
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
self.user_sender.send(event).map_err(|_| EventLoopClosed)

View file

@ -66,11 +66,18 @@ pub struct EventLoop<T: 'static> {
target: Rc<RootELW<T>>,
}
#[derive(Clone)]
pub struct EventLoopProxy<T: 'static> {
user_sender: ::calloop::channel::Sender<T>,
}
impl<T: 'static> Clone for EventLoopProxy<T> {
fn clone(&self) -> Self {
EventLoopProxy {
user_sender: self.user_sender.clone(),
}
}
}
impl<T: 'static> EventLoop<T> {
pub fn new(xconn: Arc<XConnection>) -> EventLoop<T> {
let root = unsafe { (xconn.xlib.XDefaultRootWindow)(xconn.display) };