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);Source§impl<T: ?Sized> Box<'_, T>
impl<T: ?Sized> Box<'_, T>
Sourcepub fn as_non_null(boxed: &Self) -> NonNull<T>
pub fn as_non_null(boxed: &Self) -> NonNull<T>
Get a NonNull pointer pointing to the Box’s contents.
The pointer is not valid for writes.
The caller must ensure that the Box outlives the pointer this
function returns, or else it will end up dangling.
§Example
use oxc_allocator::{Allocator, Box};
let allocator = Allocator::new();
let boxed = Box::new_in(123_u64, &allocator);
let ptr = Box::as_non_null(&boxed);Sourcepub fn into_non_null(boxed: Self) -> NonNull<T>
pub fn into_non_null(boxed: Self) -> NonNull<T>
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
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
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<'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
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
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.