pub trait CopyInto {
type Output<'arena>: 'arena;
// Required method
fn copy_into<'arena, A>(&self, arena: &'arena A) -> Self::Output<'arena>
where A: Arena;
}Expand description
A deep copy of a value into an arena, rebinding every internal reference.
Implementors copy all of their arena-resident data (byte slices, nested references, slices of children) into the given arena, so the output is self-contained: it stays valid after the arena the input lived in is dropped or reset.
use mago_allocator::prelude::*;
struct Name<'arena> {
value: &'arena [u8],
}
impl CopyInto for Name<'_> {
type Output<'arena> = Name<'arena>;
fn copy_into<'arena, A>(&self, arena: &'arena A) -> Self::Output<'arena>
where
A: Arena,
{
Name { value: arena.alloc_slice_copy(self.value) }
}
}
let source = LocalArena::new();
let target = LocalArena::new();
let name = Name { value: source.alloc_slice_copy(b"App\\Collection") };
let copied = name.copy_into(&target);
drop(source);
assert_eq!(copied.value, b"App\\Collection");Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".