pub trait CloneIn<'new_alloc>: Sized {
type Cloned;
// Required method
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned;
// Provided method
fn clone_in_with_semantic_ids(
&self,
allocator: &'new_alloc Allocator,
) -> Self::Cloned { ... }
}
Expand description
A trait to explicitly clone an object into an arena allocator.
As a convention Cloned
associated type should always be the same as Self
,
It’d only differ in the lifetime, Here’s an example:
impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for Struct<'old_alloc> {
type Cloned = Struct<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Struct { a: self.a.clone_in(allocator), b: self.b.clone_in(allocator) }
}
}
Implementations of this trait on non-allocated items usually short-circuit to Clone::clone
;
However, it isn’t guaranteed.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn clone_in_with_semantic_ids(
&self,
allocator: &'new_alloc Allocator,
) -> Self::Cloned
fn clone_in_with_semantic_ids( &self, allocator: &'new_alloc Allocator, ) -> Self::Cloned
Almost identical as clone_in
, but for some special type, it will also clone the semantic ids.
Please use this method only if you make sure semantic info is synced with the ast node.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.