diff --git a/crates/oxc_allocator/src/clone_in.rs b/crates/oxc_allocator/src/clone_in.rs index 7be119ae2baca2..9e7e16b6a7a3c7 100644 --- a/crates/oxc_allocator/src/clone_in.rs +++ b/crates/oxc_allocator/src/clone_in.rs @@ -1,4 +1,21 @@ use crate::{Allocator, Box, Vec}; + +/// 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, alloc: &'new_alloc Allocator) -> Self::Cloned { +/// Struct { a: self.a.clone_in(alloc), b: self.b.clone_in(alloc) } +/// } +/// } +/// ``` +/// +/// Implementations of this trait on non-allocated items short-circuit to `Clone::clone`. +/// pub trait CloneIn<'new_alloc>: Sized { type Cloned;