Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 94fbcaf

Browse files
committed
Manually implement Clone for Sender/SyncSender
The automatically derived implementation will only work if the channel's item type is also implementing Clone, which is not required here. Fixes #494
1 parent 34b8df4 commit 94fbcaf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/main_context_channel.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,15 @@ unsafe extern "C" fn finalize<T, F: FnMut(T) -> Continue + 'static>(
321321
/// See [`MainContext::channel()`] for how to create such a `Sender`.
322322
///
323323
/// [`MainContext::channel()`]: struct.MainContext.html#method.channel
324-
#[derive(Clone, Debug)]
324+
#[derive(Debug)]
325325
pub struct Sender<T>(Option<Channel<T>>);
326326

327+
impl<T> Clone for Sender<T> {
328+
fn clone(&self) -> Sender<T> {
329+
Sender(self.0.clone())
330+
}
331+
}
332+
327333
impl<T> Sender<T> {
328334
/// Sends a value to the channel.
329335
pub fn send(&self, t: T) -> Result<(), mpsc::SendError<T>> {
@@ -363,9 +369,15 @@ impl<T> Drop for Sender<T> {
363369
/// See [`MainContext::sync_channel()`] for how to create such a `SyncSender`.
364370
///
365371
/// [`MainContext::sync_channel()`]: struct.MainContext.html#method.sync_channel
366-
#[derive(Clone, Debug)]
372+
#[derive(Debug)]
367373
pub struct SyncSender<T>(Option<Channel<T>>);
368374

375+
impl<T> Clone for SyncSender<T> {
376+
fn clone(&self) -> SyncSender<T> {
377+
SyncSender(self.0.clone())
378+
}
379+
}
380+
369381
impl<T> SyncSender<T> {
370382
/// Sends a value to the channel and blocks if the channel is full.
371383
pub fn send(&self, t: T) -> Result<(), mpsc::SendError<T>> {

0 commit comments

Comments
 (0)