59 lines
1.3 KiB
Rust
59 lines
1.3 KiB
Rust
use std::num::NonZeroU32;
|
|
|
|
#[macro_export]
|
|
#[doc(hidden)]
|
|
macro_rules! _ptrs {
|
|
($(
|
|
$(#[$outer:meta])*
|
|
$vis:vis struct $name:ident;
|
|
)*) => {$(
|
|
$(#[$outer])*
|
|
#[derive(
|
|
Debug,
|
|
Clone,
|
|
Copy,
|
|
PartialEq,
|
|
Eq,
|
|
PartialOrd,
|
|
Ord,
|
|
Hash,
|
|
)]
|
|
$vis struct $name(::core::num::NonZeroU32);
|
|
|
|
impl $name {
|
|
/// Create instance of the pointer.
|
|
pub const fn new(v: ::core::num::NonZeroU32) -> Self {
|
|
Self(v)
|
|
}
|
|
|
|
pub const fn get(&self) -> ::core::num::NonZeroU32 {
|
|
self.0
|
|
}
|
|
}
|
|
|
|
impl ::core::convert::From<$name> for ::core::num::NonZeroU32 {
|
|
fn from(value: $name) -> Self {
|
|
value.get()
|
|
}
|
|
}
|
|
|
|
impl ::core::convert::From<::core::num::NonZeroU32> for $name {
|
|
fn from(value: ::core::num::NonZeroU32) -> Self {
|
|
Self::new(value)
|
|
}
|
|
}
|
|
|
|
impl $crate::arena::ptr::Ptr for $name {
|
|
fn get(&self) -> ::core::num::NonZeroU32 {
|
|
self.0
|
|
}
|
|
}
|
|
)*};
|
|
}
|
|
|
|
/// Pointer in arena.
|
|
pub trait Ptr {
|
|
fn get(&self) -> NonZeroU32;
|
|
}
|
|
|
|
pub use crate::_ptrs as define;
|