diff --git a/src/rust.rs b/src/rust.rs index 20b4a3b7b..30878376a 100644 --- a/src/rust.rs +++ b/src/rust.rs @@ -532,6 +532,14 @@ impl GCMethods for Value { } impl + Copy> Heap { + pub fn new(v: T) -> Heap + where Heap: Default + { + let mut ptr = Heap::default(); + ptr.set(v); + ptr + } + pub fn set(&mut self, v: T) { unsafe { let ptr = self.ptr.get(); @@ -556,8 +564,18 @@ impl + Copy> Heap { } } -impl Default for Heap<*mut JSObject> { - fn default() -> Heap<*mut JSObject> { +impl + Copy> Clone for Heap + where Heap: Default +{ + fn clone(&self) -> Self { + Heap::new(self.get()) + } +} + +impl Default for Heap<*mut T> + where *mut T: GCMethods<*mut T> + Copy +{ + fn default() -> Heap<*mut T> { Heap { ptr: UnsafeCell::new(ptr::null_mut()) } @@ -581,6 +599,11 @@ impl + Copy> Drop for Heap { } } +impl + Copy + PartialEq> PartialEq for Heap { + fn eq(&self, other: &Self) -> bool { + self.get() == other.get() + } +} // ___________________________________________________________________________ // Implementations for various things in jsapi.rs