diff --git a/.travis.yml b/.travis.yml index 824c4f3..5356510 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,6 +15,7 @@ matrix: - NODROP_FEATURES='use_needs_drop' - rust: nightly env: + - FEATURES='use_union' - NODROP_FEATURES='use_union' branches: only: diff --git a/Cargo.toml b/Cargo.toml index e14cb7f..ae04b7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "arrayvec" -version = "0.3.16" +version = "0.3.17" authors = ["bluss"] license = "MIT/Apache-2.0" @@ -15,10 +15,11 @@ version = "0.2.12" default-features = false [dependencies.nodrop] -version = "0.1.6" +version = "0.1.8" path = "nodrop" default-features = false [features] default = ["std"] std = ["odds/std", "nodrop/std"] +use_union = ["nodrop/use_union"] diff --git a/Makefile b/Makefile index bed90ff..2617b1e 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -DOCCRATES = arrayvec nodrop odds +DOCCRATES = arrayvec nodrop nodrop_union odds # deps to delete the generated docs RMDOCS = -FEATURES = odds/unstable +FEATURES = "odds/unstable nodrop/use_union" VERSIONS = $(patsubst %,target/VERS/%,$(DOCCRATES)) diff --git a/README.rst b/README.rst index 78030b1..6fd1407 100644 --- a/README.rst +++ b/README.rst @@ -22,6 +22,11 @@ __ http://bluss.github.io/arrayvec Recent Changes (arrayvec) ------------------------- +- 0.3.17 + + - Added crate feature ``use_union`` which forwards to the nodrop crate feature + - Added methods ``.is_full()`` to ``ArrayVec`` and ``ArrayString``. + - 0.3.16 - Added method ``.retain()`` to ``ArrayVec``. @@ -91,6 +96,17 @@ Recent Changes (nodrop) optimization, which skips overwriting if the inner value does not need drop. +Recent Changes (nodrop-union) +----------------------- + +- 0.1.9 + + - Add ``Copy, Clone`` implementations + +- 0.1.8 + + - Initial release + License ======= diff --git a/nodrop-union/Cargo.toml b/nodrop-union/Cargo.toml index 1ee2cfa..3e693c9 100644 --- a/nodrop-union/Cargo.toml +++ b/nodrop-union/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "nodrop-union" -version = "0.1.8" +version = "0.1.9" authors = ["bluss"] license = "MIT/Apache-2.0" description = "A wrapper type to inhibit drop (destructor). Implementation crate for nodrop, the untagged unions implementation (which is unstable / requires nightly) as of this writing." -documentation = "http://bluss.github.io/arrayvec/doc/nodrop" +documentation = "http://bluss.github.io/arrayvec/doc/nodrop_union" repository = "https://github.com/bluss/arrayvec" keywords = ["container", "drop", "no_std"] diff --git a/nodrop-union/src/lib.rs b/nodrop-union/src/lib.rs index a7fc9e2..16fd941 100644 --- a/nodrop-union/src/lib.rs +++ b/nodrop-union/src/lib.rs @@ -1,19 +1,21 @@ //! -//! The **nodrop** crate has the following cargo feature flags: +//! **nodrop-union** is the untagged unions (requires Rust nightly channel and +//! unstable as of this writing) implementation for the **nodrop** crate. //! -//! - `std` -//! - Optional, enabled by default -//! - Requires Rust 1.6 *to disable* -//! - Use libstd -//! - `use_needs_drop` -//! - Optional -//! - Requires nightly channel. -//! - Use `needs_drop` to skip overwriting if not necessary -//! - `use_union` -//! - Optional -//! - Requires nightly channel -//! - Using untagged union, finally we have an implementation of `NoDrop` without hacks, -//! for example the fact that `NoDrop` never has a destructor anymore. +//! It is intended you use this through the **nodrop** crate with the `use_union` +//! crate feature enabled. +//! +//! This is the future implementation of nodrop, once it is stable. +//! +//! This implementation is a lot better: +//! +//! - Does not have a destructor at all +//! - Can be Copy if T is Copy +//! - No space overhead / no runtime flag +//! +//! This means that this implementation has extensions that the +//! stable nodrop does not yet have, which is something to be aware of if +//! you are switching. //! #![feature(untagged_unions)] @@ -25,10 +27,24 @@ extern crate core as std; use std::ops::{Deref, DerefMut}; #[allow(unions_with_drop_fields)] +#[derive(Copy)] union UnionFlag { value: T, } +impl Clone for UnionFlag { + fn clone(&self) -> Self { + unsafe { + UnionFlag { value: self.value.clone() } + } + } +} + +/// A type holding **T** that will not call its destructor on drop +/// +/// The untagged unions implementation of `NoDrop` is Copy where T: Copy, +/// which was not possible in the stable implementation. +#[derive(Copy, Clone)] pub struct NoDrop(UnionFlag); impl NoDrop { diff --git a/src/lib.rs b/src/lib.rs index f651811..15dfc7f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,12 @@ //! - Optional, enabled by default //! - Requires Rust 1.6 *to disable* //! - Use libstd +//! +//! - `use_union` +//! - Optional +//! - Requires Rust nightly channel +//! - Use the unstable feature untagged unions for the internal implementation, +//! which has reduced space overhead #![cfg_attr(not(feature="std"), no_std)] extern crate odds; extern crate nodrop;