Skip to content

Commit

Permalink
docs: add comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvxa committed Aug 7, 2024
1 parent 29114b0 commit ebcb489
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down

0 comments on commit ebcb489

Please sign in to comment.