summaryrefslogtreecommitdiff
path: root/crates/typst-utils
diff options
context:
space:
mode:
author+merlan #flirora <uruwi@protonmail.com>2024-05-25 15:17:07 -0400
committerGitHub <noreply@github.com>2024-05-25 19:17:07 +0000
commit1694327b707621454606d7c3ffd0ed7f603d87e9 (patch)
treea3f501bd26ca59c3f24a4d60c95557000f341300 /crates/typst-utils
parent4929262610016280b455f3a79f4b150724a5acbe (diff)
Refactor `Capable::vtable` to return `Option<NonNull<()>>` (#4252)
Diffstat (limited to 'crates/typst-utils')
-rw-r--r--crates/typst-utils/src/fat.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/crates/typst-utils/src/fat.rs b/crates/typst-utils/src/fat.rs
index d3c9bb20..b31a2bb1 100644
--- a/crates/typst-utils/src/fat.rs
+++ b/crates/typst-utils/src/fat.rs
@@ -7,6 +7,7 @@
use std::alloc::Layout;
use std::mem;
+use std::ptr::NonNull;
/// Create a fat pointer from a data address and a vtable address.
///
@@ -39,9 +40,11 @@ pub unsafe fn from_raw_parts_mut<T: ?Sized>(data: *mut (), vtable: *const ()) ->
/// # Safety
/// Must only be called when `T` is a `dyn Trait`.
#[track_caller]
-pub unsafe fn vtable<T: ?Sized>(ptr: *const T) -> *const () {
+pub unsafe fn vtable<T: ?Sized>(ptr: *const T) -> NonNull<()> {
debug_assert_eq!(Layout::new::<*const T>(), Layout::new::<FatPointer>());
- mem::transmute_copy::<*const T, FatPointer>(&ptr).vtable
+ NonNull::new_unchecked(
+ mem::transmute_copy::<*const T, FatPointer>(&ptr).vtable as *mut (),
+ )
}
/// The memory representation of a trait object pointer.