From 6f6007156b2ddd5ceee356db5d79f4491bf011f3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Wed, 15 Mar 2023 14:26:03 +0000 Subject: [PATCH] Introduce Box::new in mini_core --- example/mini_core.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/example/mini_core.rs b/example/mini_core.rs index 1f9db1eb2a9..73b83b89f6d 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -518,6 +518,17 @@ pub struct Box(Unique, ()); impl, U: ?Sized> CoerceUnsized> for Box {} +impl Box { + pub fn new(val: T) -> Box { + unsafe { + let size = intrinsics::size_of::(); + let ptr = libc::malloc(size); + intrinsics::copy(&val as *const T as *const u8, ptr, size); + Box(Unique { pointer: NonNull(ptr as *const T), _marker: PhantomData }, ()) + } + } +} + impl Drop for Box { fn drop(&mut self) { // drop is currently performed by compiler.