Skip to content

Commit

Permalink
fix(core): implement Clone manually on Channel. (tauri-apps#12876)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Mar 3, 2025
1 parent dc78dfe commit 755533c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/channel-clone.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": "patch:bug"
---

Removed `TSend: Clone` requirement for `Channel<TSend>` by implementing `Clone` manually instead of driving it.
11 changes: 10 additions & 1 deletion crates/tauri/src/ipc/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ static CHANNEL_DATA_COUNTER: AtomicU32 = AtomicU32::new(0);
pub struct ChannelDataIpcQueue(pub(crate) Arc<Mutex<HashMap<u32, InvokeResponseBody>>>);

/// An IPC channel.
#[derive(Clone)]
pub struct Channel<TSend = InvokeResponseBody> {
id: u32,
on_message: Arc<dyn Fn(InvokeResponseBody) -> crate::Result<()> + Send + Sync>,
Expand All @@ -49,6 +48,16 @@ const _: () = {
struct Channel<TSend>(std::marker::PhantomData<TSend>);
};

impl<TSend> Clone for Channel<TSend> {
fn clone(&self) -> Self {
Self {
id: self.id,
on_message: self.on_message.clone(),
phantom: Default::default(),
}
}
}

impl<TSend> Serialize for Channel<TSend> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down

0 comments on commit 755533c

Please sign in to comment.