The return type some methods involves:
pub struct MemoryBlock {
pub ptr: NonNull<u8>,
pub size: usize,
}
A pointer and a size, that sounds familiar.
Perhaps a dedicated struct is not needed and this could be NonNull<[u8]> instead?
NonNull::cast can be used to cast to any thin pointer type, similar to accessing the MemoryBlock::ptr field. PR rust-lang/rust#71940 proposes NonNull<[T]>::len for accessing the size, and NonNull<[T]>::slice_from_raw_parts for constructing a new value. (I feel that these would be good to have regardless of what happens to MemoryBlock, and I expect their existence be uncontroversial given the precedent of <*const [T]>::len and ptr::slice_from_raw_parts.)
The return type some methods involves:
A pointer and a size, that sounds familiar.
Perhaps a dedicated struct is not needed and this could be
NonNull<[u8]>instead?NonNull::castcan be used to cast to any thin pointer type, similar to accessing theMemoryBlock::ptrfield. PR rust-lang/rust#71940 proposesNonNull<[T]>::lenfor accessing the size, andNonNull<[T]>::slice_from_raw_partsfor constructing a new value. (I feel that these would be good to have regardless of what happens toMemoryBlock, and I expect their existence be uncontroversial given the precedent of<*const [T]>::lenandptr::slice_from_raw_parts.)