From c38659ddea832dabf65691cdb64f01279acdc411 Mon Sep 17 00:00:00 2001 From: 0xc0001a2040 Date: Tue, 20 Dec 2022 23:18:13 +0000 Subject: [PATCH] Add fmt::Pointer impl for bevy_ptr::{Ptr, PtrMut, OwnedPtr} (#6980) # Objective - `bevy_ptr::{Ptr, PtrMut, OwnedPtr}` wrap raw pointers and should be printable using pointer formatting. ## Solution - Add a `core::fmt::Pointer` impl for `Ptr`, `PtrMut` and `OwnedPtr` based on the wrapped `NonNull` pointer. --- ## Changelog - Added a `core::fmt::Pointer` impl to `Ptr`, `PtrMut` and `OwnedPtr`. Co-authored-by: MrGunflame --- crates/bevy_ptr/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/bevy_ptr/src/lib.rs b/crates/bevy_ptr/src/lib.rs index 4aec221350..2163e64784 100644 --- a/crates/bevy_ptr/src/lib.rs +++ b/crates/bevy_ptr/src/lib.rs @@ -2,6 +2,7 @@ #![no_std] #![warn(missing_docs)] +use core::fmt::{self, Formatter, Pointer}; use core::{ cell::UnsafeCell, marker::PhantomData, mem::ManuallyDrop, num::NonZeroUsize, ptr::NonNull, }; @@ -94,6 +95,13 @@ macro_rules! impl_ptr { Self(inner, PhantomData) } } + + impl Pointer for $ptr<'_> { + #[inline] + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + Pointer::fmt(&self.0, f) + } + } }; }