Skip to content

Commit

Permalink
generalise UserEventSender: Clone (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad authored Aug 29, 2023
1 parent 68f5b27 commit d6eff49
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,21 @@ pub enum EventLoopSendError
}

/// Allows user events to be sent to the event loop from other threads.
#[derive(Clone)]
pub struct UserEventSender<UserEventType: 'static>
{
inner: UserEventSenderInnerType<UserEventType>
}

impl<UserEventType> Clone for UserEventSender<UserEventType>
{
fn clone(&self) -> Self
{
UserEventSender {
inner: self.inner.clone()
}
}
}

impl<UserEventType> UserEventSender<UserEventType>
{
pub(crate) fn new(inner: UserEventSenderInnerType<UserEventType>) -> Self
Expand Down
11 changes: 10 additions & 1 deletion src/window_internal_glutin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,12 +950,21 @@ pub(crate) enum UserEventGlutin<UserEventType: 'static>
UserEvent(UserEventType)
}

#[derive(Clone)]
pub struct UserEventSenderGlutin<UserEventType: 'static>
{
event_proxy: EventLoopProxy<UserEventGlutin<UserEventType>>
}

impl<UserEventType> Clone for UserEventSenderGlutin<UserEventType>
{
fn clone(&self) -> Self
{
UserEventSenderGlutin {
event_proxy: self.event_proxy.clone()
}
}
}

impl<UserEventType> UserEventSenderGlutin<UserEventType>
{
fn new(event_proxy: EventLoopProxy<UserEventGlutin<UserEventType>>) -> Self
Expand Down
11 changes: 10 additions & 1 deletion src/window_internal_web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,23 @@ impl<UserEventType: 'static> WindowHelperWeb<UserEventType>
type UserEventSenderActionType<UserEventType> =
dyn FnMut(UserEventType) -> Result<(), BacktraceError<ErrorMessage>>;

#[derive(Clone)]
pub struct UserEventSenderWeb<UserEventType>
where
UserEventType: 'static
{
action: Rc<RefCell<UserEventSenderActionType<UserEventType>>>
}

impl<UserEventType: 'static> Clone for UserEventSenderWeb<UserEventType>
{
fn clone(&self) -> Self
{
UserEventSenderWeb {
action: self.action.clone()
}
}
}

impl<UserEventType: 'static> UserEventSenderWeb<UserEventType>
{
fn new(action: Rc<RefCell<UserEventSenderActionType<UserEventType>>>) -> Self
Expand Down

0 comments on commit d6eff49

Please sign in to comment.