From d4dfdea785725c4277967665a1bacbede1838712 Mon Sep 17 00:00:00 2001 From: bluss Date: Thu, 8 Sep 2016 11:46:01 +0200 Subject: [PATCH] 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 {