nodrop-union: Implement Copy, Clone on NoDrop<T>
Clone is not so important, but Copy is, since it's structural when implemented, and adding the trait allows more versatile use of NoDrop<T>. Only the untagged unions version can implement Copy for NoDrop<T>, since it truly has no destructor.
This commit is contained in:
@@ -25,10 +25,20 @@ extern crate core as std;
|
|||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
|
|
||||||
#[allow(unions_with_drop_fields)]
|
#[allow(unions_with_drop_fields)]
|
||||||
|
#[derive(Copy)]
|
||||||
union UnionFlag<T> {
|
union UnionFlag<T> {
|
||||||
value: T,
|
value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Clone> Clone for UnionFlag<T> {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
unsafe {
|
||||||
|
UnionFlag { value: self.value.clone() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
pub struct NoDrop<T>(UnionFlag<T>);
|
pub struct NoDrop<T>(UnionFlag<T>);
|
||||||
|
|
||||||
impl<T> NoDrop<T> {
|
impl<T> NoDrop<T> {
|
||||||
|
|||||||
Reference in New Issue
Block a user