CloneIn

Trait CloneIn 

Source
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§

Source

type Cloned

The type of the cloned object.

This should always be Self with a different lifetime.

Required Methods§

Source

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned

Clone self into the given allocator. allocator may be the same one that self is already in.

Provided Methods§

Source

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.

Implementations on Foreign Types§

Source§

impl<'alloc> CloneIn<'alloc> for bool

Source§

type Cloned = bool

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for char

Source§

type Cloned = char

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for f32

Source§

type Cloned = f32

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for f64

Source§

type Cloned = f64

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for i8

Source§

type Cloned = i8

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for i16

Source§

type Cloned = i16

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for i32

Source§

type Cloned = i32

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for i64

Source§

type Cloned = i64

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for i128

Source§

type Cloned = i128

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for isize

Source§

type Cloned = isize

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for u8

Source§

type Cloned = u8

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for u16

Source§

type Cloned = u16

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for u32

Source§

type Cloned = u32

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for u64

Source§

type Cloned = u64

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for u128

Source§

type Cloned = u128

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc> CloneIn<'alloc> for usize

Source§

type Cloned = usize

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self

Source§

impl<'alloc, T, C> CloneIn<'alloc> for Option<T>
where T: CloneIn<'alloc, Cloned = C>,

Source§

type Cloned = Option<C>

Source§

fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned

Source§

fn clone_in_with_semantic_ids( &self, allocator: &'alloc Allocator, ) -> Self::Cloned

Source§

impl<'alloc, T: Copy> CloneIn<'alloc> for Cell<T>

Source§

type Cloned = Cell<T>

Source§

fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned

Source§

impl<'new_alloc> CloneIn<'new_alloc> for &str

Source§

type Cloned = &'new_alloc str

Source§

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned

Implementors§

Source§

impl<'new_alloc, K, V, CK, CV> CloneIn<'new_alloc> for HashMap<'_, K, V>
where K: CloneIn<'new_alloc, Cloned = CK>, V: CloneIn<'new_alloc, Cloned = CV>, CK: Hash + Eq,

Source§

type Cloned = HashMap<'new_alloc, CK, CV>

Source§

impl<'new_alloc, T, C> CloneIn<'new_alloc> for Box<'_, [T]>
where T: CloneIn<'new_alloc, Cloned = C>,

Source§

type Cloned = Box<'new_alloc, [C]>

Source§

impl<'new_alloc, T, C> CloneIn<'new_alloc> for Box<'_, T>
where T: CloneIn<'new_alloc, Cloned = C>,

Source§

type Cloned = Box<'new_alloc, C>

Source§

impl<'new_alloc, T, C> CloneIn<'new_alloc> for Vec<'_, T>
where T: CloneIn<'new_alloc, Cloned = C>, C: 'new_alloc,

Source§

type Cloned = Vec<'new_alloc, C>