pub struct Vec<'alloc, T>(/* private fields */);Expand description
A Vec 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. Vec::new_in and all other methods which create
a Vec will refuse to compile if called with a Drop type.
Implementations§
Source§impl<'alloc, T> Vec<'alloc, T>
impl<'alloc, T> Vec<'alloc, T>
Sourcepub fn new_in(allocator: &'alloc Allocator) -> Vec<'alloc, T>
pub fn new_in(allocator: &'alloc Allocator) -> Vec<'alloc, T>
Constructs a new, empty Vec<T>.
The vector will not allocate until elements are pushed onto it.
§Examples
use oxc_allocator::{Allocator, Vec};
let allocator = Allocator::default();
let mut vec: Vec<i32> = Vec::new_in(&allocator);
assert!(vec.is_empty());Sourcepub fn with_capacity_in(
capacity: usize,
allocator: &'alloc Allocator,
) -> Vec<'alloc, T>
pub fn with_capacity_in( capacity: usize, allocator: &'alloc Allocator, ) -> Vec<'alloc, T>
Constructs a new, empty Vec<T> with at least the specified capacity
with the provided allocator.
The vector will be able to hold at least capacity elements without
reallocating. This method is allowed to allocate for more elements than
capacity. If capacity is 0, the vector will not allocate.
It is important to note that although the returned vector has the minimum capacity specified, the vector will have a zero length.
For Vec<T> where T is a zero-sized type, there will be no allocation
and the capacity will always be u32::MAX.
§Panics
Panics if the new capacity exceeds isize::MAX bytes.
§Examples
use oxc_allocator::{Allocator, Vec};
let allocator = Allocator::default();
let mut vec = Vec::with_capacity_in(10, &allocator);
// The vector contains no items, even though it has capacity for more
assert_eq!(vec.len(), 0);
assert_eq!(vec.capacity(), 10);
// These are all done without reallocating...
for i in 0..10 {
vec.push(i);
}
assert_eq!(vec.len(), 10);
assert_eq!(vec.capacity(), 10);
// ...but this may make the vector reallocate
vec.push(11);
assert_eq!(vec.len(), 11);
assert!(vec.capacity() >= 11);
// A vector of a zero-sized type will always over-allocate, since no
// allocation is necessary
let vec_units = Vec::<()>::with_capacity_in(10, &allocator);
assert_eq!(vec_units.capacity(), usize::MAX);Sourcepub fn from_iter_in<I>(iter: I, allocator: &'alloc Allocator) -> Vec<'alloc, T>where
I: IntoIterator<Item = T>,
pub fn from_iter_in<I>(iter: I, allocator: &'alloc Allocator) -> Vec<'alloc, T>where
I: IntoIterator<Item = T>,
Create a new Vec whose elements are taken from an iterator and
allocated in the given allocator.
This is behaviorially identical to FromIterator::from_iter.
Sourcepub fn from_array_in<const N: usize>(
array: [T; N],
allocator: &'alloc Allocator,
) -> Vec<'alloc, T>
pub fn from_array_in<const N: usize>( array: [T; N], allocator: &'alloc Allocator, ) -> Vec<'alloc, T>
Create a new Vec from a fixed-size array, allocated in the given allocator.
This is preferable to from_iter_in where source is an array, as size is statically known,
and compiler is more likely to construct the values directly in arena, rather than constructing
on stack and then copying to arena.
§Examples
use oxc_allocator::{Allocator, Vec};
let allocator = Allocator::default();
let array: [u32; 4] = [1, 2, 3, 4];
let vec = Vec::from_array_in(array, &allocator);Sourcepub fn into_boxed_slice(self) -> Box<'alloc, [T]>
pub fn into_boxed_slice(self) -> Box<'alloc, [T]>
Sourcepub fn into_bump_slice(self) -> &'alloc [T]
pub fn into_bump_slice(self) -> &'alloc [T]
Trait Implementations§
Source§impl<'new_alloc, T, C> CloneIn<'new_alloc> for Vec<'_, T>where
T: CloneIn<'new_alloc, Cloned = C>,
C: 'new_alloc,
impl<'new_alloc, T, C> CloneIn<'new_alloc> for Vec<'_, T>where
T: CloneIn<'new_alloc, Cloned = C>,
C: 'new_alloc,
Source§fn clone_in(
&self,
allocator: &'new_alloc Allocator,
) -> <Vec<'_, T> as CloneIn<'new_alloc>>::Cloned
fn clone_in( &self, allocator: &'new_alloc Allocator, ) -> <Vec<'_, T> as CloneIn<'new_alloc>>::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,
) -> <Vec<'_, T> as CloneIn<'new_alloc>>::Cloned
fn clone_in_with_semantic_ids( &self, allocator: &'new_alloc Allocator, ) -> <Vec<'_, T> as CloneIn<'new_alloc>>::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<T> ConcatElement for Vec<'_, T>where
T: ESTree,
Available on crate feature serialize only.
impl<T> ConcatElement for Vec<'_, T>where
T: ESTree,
serialize only.fn push_to_sequence<S>(&self, seq: &mut S)where
S: SequenceSerializer,
Source§impl<T> ContentEq for Vec<'_, T>where
T: ContentEq,
Blanket implementation for oxc_allocator::Vec types
impl<T> ContentEq for Vec<'_, T>where
T: ContentEq,
Blanket implementation for oxc_allocator::Vec types
§Warning
This implementation is slow compared to PartialEq for native types which are Copy (e.g. u32).
Prefer comparing the 2 vectors using == if they contain such native types (e.g. Vec<u32>).
https://godbolt.org/z/54on5sMWc
Source§fn content_eq(&self, other: &Vec<'_, T>) -> bool
fn content_eq(&self, other: &Vec<'_, T>) -> bool
self and other to be equal.Source§fn content_ne(&self, other: &Self) -> bool
fn content_ne(&self, other: &Self) -> bool
self and other not to be equal.
The default implementation is almost always
sufficient, and should not be overridden without very good reason.Source§impl<T> ESTree for Vec<'_, T>where
T: ESTree,
Available on crate features serialize only.
impl<T> ESTree for Vec<'_, T>where
T: ESTree,
serialize only.fn serialize<S>(&self, serializer: S)where
S: Serializer,
Source§impl<'i, T> IntoIterator for &'i Vec<'_, T>
impl<'i, T> IntoIterator for &'i Vec<'_, T>
Source§impl<'i, T> IntoIterator for &'i mut Vec<'_, T>
impl<'i, T> IntoIterator for &'i mut Vec<'_, T>
Source§impl<'alloc, T> IntoIterator for Vec<'alloc, T>
impl<'alloc, T> IntoIterator for Vec<'alloc, T>
Source§impl<T> Serialize for Vec<'_, T>where
T: Serialize,
Available on crate features serialize only.
impl<T> Serialize for Vec<'_, T>where
T: Serialize,
serialize only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<'a, T> TakeIn<'a> for Vec<'a, T>
impl<'a, T> TakeIn<'a> for Vec<'a, T>
Source§fn take_in<A>(&mut self, allocator_accessor: A) -> Selfwhere
A: AllocatorAccessor<'a>,
fn take_in<A>(&mut self, allocator_accessor: A) -> Selfwhere
A: AllocatorAccessor<'a>,
Source§fn take_in_box<A>(&mut self, allocator_accessor: A) -> Box<'a, Self>where
A: AllocatorAccessor<'a>,
fn take_in_box<A>(&mut self, allocator_accessor: A) -> Box<'a, Self>where
A: AllocatorAccessor<'a>,
impl<'alloc, T> Eq for Vec<'alloc, T>where
T: Eq,
impl<'alloc, T> StructuralPartialEq for Vec<'alloc, T>
impl<T> Sync for Vec<'_, T>where
T: Sync,
SAFETY: Even though Bump is not Sync, we can make Vec<T> Sync if T is Sync because:
-
No public methods allow access to the
&BumpthatVeccontains (inRawVec), so user cannot illegally obtain 2&Bumps on different threads viaVec. -
All internal methods which access the
&Bumptake a&mut self.&mut Veccannot be transferred across threads, and nor can an ownedVec(Vecis notSend). Therefore these methods taking&mut selfcan be sure they’re not operating on aVecwhich has been moved across threads.
Note: Vec CANNOT be Send, even if T is Send, because that would allow 2 Vecs on different
threads to both allocate into same arena simultaneously. Bump is not thread-safe, and this would
be undefined behavior.
Auto Trait Implementations§
impl<'alloc, T> Freeze for Vec<'alloc, T>
impl<'alloc, T> !RefUnwindSafe for Vec<'alloc, T>
impl<'alloc, T> !Send for Vec<'alloc, T>
impl<'alloc, T> Unpin for Vec<'alloc, T>
impl<'alloc, T> !UnwindSafe for Vec<'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
Source§impl<I, C> CompactStringExt for C
impl<I, C> CompactStringExt for C
Source§fn concat_compact(self) -> CompactString
fn concat_compact(self) -> CompactString
CompactString Read moreSource§fn join_compact<S>(self, separator: S) -> CompactString
fn join_compact<S>(self, separator: S) -> CompactString
CompactString Read moreSource§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more