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 @@ -52,6 +52,7 @@ harness = false
[features]
default = ["std"]
std = []
may_dangle = []

[profile.bench]
debug = true
Expand Down
10 changes: 10 additions & 0 deletions src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ pub struct ArrayVec<T, const CAP: usize> {
xs: [MaybeUninit<T>; CAP],
}

#[cfg(feature = "may_dangle")]
unsafe impl<#[may_dangle] T, const CAP: usize> Drop for ArrayVec<T, CAP> {
fn drop(&mut self) {
self.clear();

// MaybeUninit inhibits array's drop
}
}

#[cfg(not(feature = "may_dangle"))]
impl<T, const CAP: usize> Drop for ArrayVec<T, CAP> {
fn drop(&mut self) {
self.clear();
Expand Down
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@
//! - `zeroize`
//! - Optional
//! - Implement `Zeroize` for ArrayVec and ArrayString
//!
//! - `may_dangle`
//! - Optional and unstable
//! - Requires nightly toolchain
//! - Makes compiler less strict about storing references with a lifetime in ArrayVec,
//! see [Rustonomicon](https://doc.rust-lang.org/1.42.0/nomicon/dropck.html#an-escape-hatch).
//!
//! ## Rust Version
//!
//! This version of arrayvec requires Rust 1.51 or later.
//!
#![doc(html_root_url="https://docs.rs/arrayvec/0.7/")]
#![cfg_attr(not(feature="std"), no_std)]
#![cfg_attr(feature = "may_dangle", feature(dropck_eyepatch))]

#[cfg(feature="serde")]
extern crate serde;
Expand Down
Loading