chiark / gitweb /
unsized
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 14 Nov 2024 22:33:50 +0000 (22:33 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 14 Nov 2024 22:33:50 +0000 (22:33 +0000)
src/lib.rs
src/test.rs

index bae5e8261b07561bc128e678ec4dbf3aa1aa9b41..7be9207f5cf18adfa95ca310f24de485d580c42c 100644 (file)
@@ -13,7 +13,7 @@ use std::ptr::NonNull;
 ///
 /// Ensuring that `Ptr`s are freed at the right time is up to the caller.
 /// But aliasing, drop, etc., is (largely) handled by the library.
-pub struct Ptr<T> {
+pub struct Ptr<T: ?Sized> {
     /// # SAFETY
     ///
     /// Invariants (only while valid, but we can rely on them
index eba2cd40e5814de8d2efb6722856551b69a0f694..996db00cd817eaddf37d92ff4f6c68484de4b1d7 100644 (file)
@@ -41,3 +41,11 @@ fn demo() {
 
     drop(l);
 }
+
+#[test]
+fn unsize() {
+    let mut noalias = unsafe { NoAliasSingleton::init() };
+    let p = Ptr::new_heap("hi");
+    println!("{}", p.borrow(&noalias));
+    unsafe { p.free_heap(&mut noalias) };
+}