Skip to content

Commit

Permalink
Merge pull request #108 from RustyYato/object-arc-clone
Browse files Browse the repository at this point in the history
implement shallow_clone for `RObject`/`DynTrait`
  • Loading branch information
rodrimati1992 committed Aug 1, 2023
2 parents 8cd2f0c + d37d4d7 commit 5bdad32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions abi_stable/src/erased_types/dyn_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,19 @@ mod priv_ {
}
}

impl<'lt, I, EV: Clone> DynTrait<'lt, crate::std_types::RArc<()>, I, EV> {
/// Does a shallow clone of the object, just incrementing the reference counter
pub fn shallow_clone(&self) -> Self {
Self {
object: self.object.clone(),
vtable: self.vtable,
extra_value: self.extra_value.clone(),
_marker: self._marker,
_marker2: self._marker2,
}
}
}

impl<'borr, P, I, EV> Drop for DynTrait<'borr, P, I, EV>
where
P: GetPointerKind,
Expand Down
11 changes: 11 additions & 0 deletions abi_stable/src/sabi_trait/robject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,17 @@ where
}
}

impl<'lt, I, V> RObject<'lt, crate::std_types::RArc<()>, I, V> {
/// Does a shallow clone of the object, just incrementing the reference counter
pub fn shallow_clone(&self) -> Self {
Self {
vtable: self.vtable,
ptr: self.ptr.clone(),
_marker: PhantomData,
}
}
}

impl<P, I, V> Drop for RObject<'_, P, I, V>
where
P: GetPointerKind,
Expand Down

0 comments on commit 5bdad32

Please sign in to comment.