diff --git a/src/index_map.rs b/src/index_map.rs index fb16614..4a23352 100644 --- a/src/index_map.rs +++ b/src/index_map.rs @@ -289,6 +289,19 @@ impl Default for FrozenIndexMap { } } +impl Clone for FrozenIndexMap { + fn clone(&self) -> Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { + map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(), + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; + } +} + impl PartialEq for FrozenIndexMap { fn eq(&self, other: &Self) -> bool { assert!(!self.in_use.get()); diff --git a/src/index_set.rs b/src/index_set.rs index 735810b..2391327 100644 --- a/src/index_set.rs +++ b/src/index_set.rs @@ -250,6 +250,19 @@ impl Default for FrozenIndexSet { } } +impl Clone for FrozenIndexSet { + fn clone(&self) -> Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { + set: unsafe { self.set.get().as_ref().unwrap() }.clone().into(), + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; + } +} + impl PartialEq for FrozenIndexSet { fn eq(&self, other: &Self) -> bool { assert!(!self.in_use.get()); diff --git a/src/map.rs b/src/map.rs index 38dcd16..befa3e6 100644 --- a/src/map.rs +++ b/src/map.rs @@ -270,6 +270,19 @@ impl Default for FrozenMap { } } +impl Clone for FrozenMap { + fn clone(&self) -> Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { + map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(), + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; + } +} + /// Append-only version of `std::collections::BTreeMap` where /// insertion does not require mutable access pub struct FrozenBTreeMap { @@ -496,6 +509,19 @@ impl Default for FrozenBTreeMap { } } +impl Clone for FrozenBTreeMap { + fn clone(&self) -> Self { + assert!(!self.in_use.get()); + self.in_use.set(true); + let self_clone = Self { + map: unsafe { self.map.get().as_ref().unwrap() }.clone().into(), + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; + } +} + impl PartialEq for FrozenMap { fn eq(&self, other: &Self) -> bool { assert!(!self.in_use.get()); diff --git a/src/sync.rs b/src/sync.rs index 150ecc9..4e2fdc2 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -415,6 +415,14 @@ impl std::convert::AsMut> for FrozenMap { } } +impl Clone for FrozenMap { + fn clone(&self) -> Self { + Self { + map: self.map.read().unwrap().clone().into(), + } + } +} + impl PartialEq for FrozenMap { fn eq(&self, other: &Self) -> bool { let self_ref: &HashMap = &self.map.read().unwrap(); @@ -514,7 +522,7 @@ impl FrozenVec { /// Returns an iterator over the vector. pub fn iter(&self) -> Iter<'_, T> { self.into_iter() - } + } } /// Iterator over FrozenVec, obtained via `.iter()` @@ -599,6 +607,14 @@ impl Default for FrozenVec { } } +impl Clone for FrozenVec { + fn clone(&self) -> Self { + Self { + vec: self.vec.read().unwrap().clone().into(), + } + } +} + impl PartialEq for FrozenVec { fn eq(&self, other: &Self) -> bool { let self_ref: &Vec = &self.vec.read().unwrap(); @@ -1053,6 +1069,12 @@ impl Default for FrozenBTreeMap { } } +impl Clone for FrozenBTreeMap { + fn clone(&self) -> Self { + Self(self.0.read().unwrap().clone().into()) + } +} + impl PartialEq for FrozenBTreeMap { fn eq(&self, other: &Self) -> bool { let self_ref: &BTreeMap = &self.0.read().unwrap(); diff --git a/src/vec.rs b/src/vec.rs index e93f7a3..691bee4 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -216,6 +216,14 @@ impl Default for FrozenVec { } } +impl Clone for FrozenVec { + fn clone(&self) -> Self { + Self { + vec: unsafe { self.vec.get().as_ref().unwrap() }.clone().into(), + } + } +} + impl From> for FrozenVec { fn from(vec: Vec) -> Self { Self {