From d4dfdea785725c4277967665a1bacbede1838712 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 8 Sep 2016 11:46:01 +0200 Subject: [PATCH 1/5] nodrop-union: Implement Copy, Clone on NoDrop Clone is not so important, but Copy is, since it's structural when implemented, and adding the trait allows more versatile use of NoDrop. Only the untagged unions version can implement Copy for NoDrop, since it truly has no destructor. --- nodrop-union/src/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nodrop-union/src/lib.rs b/nodrop-union/src/lib.rs index a7fc9e2..94a5061 100644 --- a/nodrop-union/src/lib.rs +++ b/nodrop-union/src/lib.rs @@ -25,10 +25,20 @@ 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() } + } + } +} + +#[derive(Copy, Clone)] pub struct NoDrop(UnionFlag); impl NoDrop { From a91f077e8f278d614b698b1a66a63cd02249aa50 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 8 Sep 2016 11:46:01 +0200 Subject: [PATCH 2/5] nodrop-union: Update docs --- nodrop-union/src/lib.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/nodrop-union/src/lib.rs b/nodrop-union/src/lib.rs index 94a5061..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)] @@ -38,6 +40,10 @@ impl Clone for UnionFlag { } } +/// 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); From c2f6156b425970ec1541835d152c65a7ced7f155 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 8 Sep 2016 11:46:01 +0200 Subject: [PATCH 3/5] nodrop-union 0.1.9 --- README.rst | 11 +++++++++++ nodrop-union/Cargo.toml | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 78030b1..564520b 100644 --- a/README.rst +++ b/README.rst @@ -91,6 +91,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"] From 8785860ec4f54714015b97749c6e79e61b0947cd Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 8 Sep 2016 11:46:01 +0200 Subject: [PATCH 4/5] arrayvec 0.3.17 --- Cargo.toml | 5 +++-- Makefile | 4 ++-- README.rst | 5 +++++ src/lib.rs | 6 ++++++ 4 files changed, 16 insertions(+), 4 deletions(-) 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 564520b..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``. 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; From 0c21d04a752471f2d94ac2e522cf2ce4981f25c8 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 8 Sep 2016 11:46:26 +0200 Subject: [PATCH 5/5] test use_union in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) 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: