chiark / gitweb /
provide from_raw
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 15 Nov 2024 16:03:16 +0000 (16:03 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 15 Nov 2024 16:03:16 +0000 (16:03 +0000)
src/lib.rs

index f2a35f72815b8166c1de39d3691c9ef92df40c2b..4b6cceed537903b7c774d367264e9c344ecc69da 100644 (file)
@@ -401,6 +401,16 @@ impl<T: ?Sized> Ptr<T> {
         };
         t
     }
+
+    /// Make a new `Ptr` out of a raw pointer
+    ///
+    /// # SAFETY
+    ///
+    /// It is up to you to ensure that the pointer is valid for `T`,
+    /// dereferencable, and has appropriate lifespan.
+    pub unsafe fn from_raw(t: NonNull<T>) -> Self {
+        Ptr { ptr: t }
+    }
 }
 
 impl NoAliasSingleton {