Skip to content

Commit

Permalink
Add fmt::Pointer impl for bevy_ptr::{Ptr, PtrMut, OwnedPtr} (bevyengi…
Browse files Browse the repository at this point in the history
…ne#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 <mrgunflame@protonmail.com>
  • Loading branch information
2 people authored and alradish committed Jan 22, 2023
1 parent 262b820 commit bf16064
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/bevy_ptr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)
}
}
};
}

Expand Down

0 comments on commit bf16064

Please sign in to comment.