We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b42358a commit 6f60071Copy full SHA for 6f60071
example/mini_core.rs
@@ -518,6 +518,17 @@ pub struct Box<T: ?Sized>(Unique<T>, ());
518
519
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
520
521
+impl<T> Box<T> {
522
+ pub fn new(val: T) -> Box<T> {
523
+ unsafe {
524
+ let size = intrinsics::size_of::<T>();
525
+ let ptr = libc::malloc(size);
526
+ intrinsics::copy(&val as *const T as *const u8, ptr, size);
527
+ Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, ())
528
+ }
529
530
+}
531
+
532
impl<T: ?Sized> Drop for Box<T> {
533
fn drop(&mut self) {
534
// drop is currently performed by compiler.
0 commit comments