refactor(core/rust): allow Copy and Clone for Gc

This is legal for garbage-collected pointers and we only avoided the
implementation due to being careful.

Now is the first time we need that functionality.
matejcik 2 weeks ago
parent e4f81a42db
commit 79f70fc690

@ -9,11 +9,16 @@ use crate::error::Error;
use super::ffi;
/// A pointer type for values on the garbage-collected heap.
///
/// Although a garbage-collected pointer type technically should implement
/// `Copy` and `Clone`, we avoid doing this until proven necessary.
pub struct Gc<T: ?Sized>(NonNull<T>);
impl<T: ?Sized> Clone for Gc<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T: ?Sized> Copy for Gc<T> {}
impl<T> Gc<T> {
/// Allocate memory on the heap managed by the MicroPython garbage collector
/// and then place `v` into it. `v` will _not_ get its destructor called.

Loading…
Cancel
Save