pub struct Box<'alloc, T: ?Sized>(/* private fields */);Expand description
A Box without Drop, which stores its data in the arena allocator.
§No Drops
Objects allocated into Oxc memory arenas are never Dropped. Memory is released in bulk
when the allocator is dropped, without dropping the individual objects in the arena.
Therefore, it would produce a memory leak if you allocated Drop types into the arena
which own memory allocations outside the arena.
Static checks make this impossible to do. Box::new_in will refuse to compile if called
with a Drop type.
Implementations§
Source§impl<T> Box<'_, T>
impl<T> Box<'_, T>
Sourcepub fn unbox(self) -> T
pub fn unbox(self) -> T
Take ownership of the value stored in this Box, consuming the box in
the process.
§Examples
use oxc_allocator::{Allocator, Box};
let arena = Allocator::default();
// Put `5` into the arena and on the heap.
let boxed: Box<i32> = Box::new_in(5, &arena);
// Move it back to the stack. `boxed` has been consumed.
let i = boxed.unbox();
assert_eq!(i, 5);Trait Implementations§
Source§impl<'new_alloc, T, C> CloneIn<'new_alloc> for Box<'_, T>where
T: CloneIn<'new_alloc, Cloned = C>,
impl<'new_alloc, T, C> CloneIn<'new_alloc> for Box<'_, T>where
T: CloneIn<'new_alloc, Cloned = C>,
Source§fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned
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.Source§fn 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.Source§impl<T> GetAddress for Box<'_, T>
impl<T> GetAddress for Box<'_, T>
Auto Trait Implementations§
impl<'alloc, T> Freeze for Box<'alloc, T>where
T: ?Sized,
impl<'alloc, T> RefUnwindSafe for Box<'alloc, T>where
T: RefUnwindSafe + ?Sized,
impl<'alloc, T> !Send for Box<'alloc, T>
impl<'alloc, T> !Sync for Box<'alloc, T>
impl<'alloc, T> Unpin for Box<'alloc, T>
impl<'alloc, T> UnwindSafe for Box<'alloc, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more