diff --git a/src/index_map.rs b/src/index_map.rs index 50d021f..b96179f 100644 --- a/src/index_map.rs +++ b/src/index_map.rs @@ -238,9 +238,13 @@ impl Default for FrozenIndexMap { impl Clone for FrozenIndexMap { fn clone(&self) -> 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: self.in_use.clone(), - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; } } diff --git a/src/index_set.rs b/src/index_set.rs index 28819d0..59588ad 100644 --- a/src/index_set.rs +++ b/src/index_set.rs @@ -183,9 +183,13 @@ impl Default for FrozenIndexSet { impl Clone for FrozenIndexSet { fn clone(&self) -> 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: self.in_use.clone(), - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone; } } diff --git a/src/map.rs b/src/map.rs index e8cf7c1..32e79a8 100644 --- a/src/map.rs +++ b/src/map.rs @@ -272,11 +272,14 @@ impl Default for FrozenMap { impl Clone for FrozenMap { fn clone(&self) -> 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: self.in_use.clone(), - } - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone;} } /// Append-only version of `std::collections::BTreeMap` where @@ -507,9 +510,12 @@ impl Default for FrozenBTreeMap { impl Clone for FrozenBTreeMap { fn clone(&self) -> 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: self.in_use.clone(), - } - } + in_use: Cell::from(false), + }; + self.in_use.set(false); + return self_clone;} }