Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rust-version = "1.53"
unstable = []
default = ["std"]
std = []
const_new = []

# Gecko specific features. These features cause thin-vec to have the same layout
# and behaviour as nsTArray, allowing it to be used in C++ FFI. Requires
Expand Down
22 changes: 22 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
//! but it could be done if someone cared enough to implement it.
//!
//!
//! # Optional Features
//!
//! ## `const_new`
//!
//! **This feature requires Rust 1.83.**
//!
//! This feature makes `ThinVec::new()` a `const fn`.
//!
//!
//! # Gecko FFI
//!
Expand Down Expand Up @@ -516,10 +524,24 @@ impl<T> ThinVec<T> {
/// Creates a new empty ThinVec.
///
/// This will not allocate.
#[cfg(not(feature = "const_new"))]
pub fn new() -> ThinVec<T> {
ThinVec::with_capacity(0)
}

/// Creates a new empty ThinVec.
///
/// This will not allocate.
#[cfg(feature = "const_new")]
pub const fn new() -> ThinVec<T> {
unsafe {
ThinVec {
ptr: NonNull::new_unchecked(&EMPTY_HEADER as *const Header as *mut Header),
boo: PhantomData,
}
}
}

/// Constructs a new, empty `ThinVec<T>` with at least the specified capacity.
///
/// The vector will be able to hold at least `capacity` elements without
Expand Down