Skip to content

Commit

Permalink
InstancePre can impl Clone (#3510)
Browse files Browse the repository at this point in the history
Its a manually written impl, not a derive, because InstancePre<T>: Clone
does not require T: Clone.

The clone should be reasonably inexpensive: Clone for Module is just an
Arc, and Clone for Definition should also just be an Arc on the HostFunc
or Instance variants. An InstancePre shouldnt contain any
Definition::Extern variants because there is not yet a Store associated
with it- right?
  • Loading branch information
Pat Hickey authored Nov 8, 2021
1 parent 6be0f82 commit 2053e97
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/wasmtime/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,17 @@ pub struct InstancePre<T> {
_marker: std::marker::PhantomData<fn() -> T>,
}

/// InstancePre's clone does not require T: Clone
impl<T> Clone for InstancePre<T> {
fn clone(&self) -> Self {
Self {
module: self.module.clone(),
items: self.items.clone(),
_marker: self._marker,
}
}
}

impl<T> InstancePre<T> {
pub(crate) unsafe fn new(
store: &mut StoreOpaque,
Expand Down

0 comments on commit 2053e97

Please sign in to comment.