Skip to content

Commit d8becd2

Browse files
committed
Rename SimpleNonZeroPointer -> SimpleNonZeroRepr
Now it supports more than just pointers, including NonZeroU32 and NonZeroUsize Needed in DuckLogic since DuckVal is nonzero
1 parent 06943b6 commit d8becd2

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/core.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Implementations of [StaticReflect] for core types (for `#![no_std]`)
22
use crate::StaticReflect;
3-
use crate::types::{TypeInfo, SimpleNonZeroPointer};
3+
use crate::types::{TypeInfo, SimpleNonZeroRepr};
44
use std::mem::{self, ManuallyDrop};
55
use core::ptr::NonNull;
6+
use std::num::{NonZeroI32, NonZeroU32, NonZeroU8, NonZeroUsize};
67

78
macro_rules! impl_primitive {
89
($target:ty => $info:expr) => {
@@ -64,11 +65,30 @@ unsafe impl <T> StaticReflect for *const T {
6465
const TYPE_INFO: TypeInfo<'static> = TypeInfo::Pointer;
6566
}
6667

67-
unsafe impl <T> SimpleNonZeroPointer for NonNull<T> {}
68+
unsafe impl <T> SimpleNonZeroRepr for NonNull<T> {}
6869
unsafe impl <T> StaticReflect for NonNull<T> {
6970
const TYPE_INFO: TypeInfo<'static> = TypeInfo::Pointer;
7071
}
72+
unsafe impl SimpleNonZeroRepr for NonZeroUsize {}
73+
unsafe impl StaticReflect for NonZeroUsize {
74+
const TYPE_INFO: TypeInfo<'static> = <usize as StaticReflect>::TYPE_INFO;
75+
}
76+
unsafe impl SimpleNonZeroRepr for NonZeroU32 {}
77+
unsafe impl StaticReflect for NonZeroU32 {
78+
const TYPE_INFO: TypeInfo<'static> = <u32 as StaticReflect>::TYPE_INFO;
79+
}
80+
unsafe impl SimpleNonZeroRepr for NonZeroU8 {}
81+
unsafe impl StaticReflect for NonZeroU8 {
82+
const TYPE_INFO: TypeInfo<'static> = <u8 as StaticReflect>::TYPE_INFO;
83+
}
84+
unsafe impl SimpleNonZeroRepr for NonZeroI32 {}
85+
unsafe impl StaticReflect for NonZeroI32 {
86+
const TYPE_INFO: TypeInfo<'static> = <i32 as StaticReflect>::TYPE_INFO;
87+
}
7188

72-
unsafe impl <T: SimpleNonZeroPointer> StaticReflect for Option<T> {
73-
const TYPE_INFO: TypeInfo<'static> = TypeInfo::Pointer;
74-
}
89+
90+
unsafe impl <T: SimpleNonZeroRepr> StaticReflect for Option<T> {
91+
/// We have the representation as our internals,
92+
/// except for the fact we might be null
93+
const TYPE_INFO: TypeInfo<'static> = <T as StaticReflect>::TYPE_INFO;
94+
}

src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use zerogc_derive::{unsafe_gc_impl};
1313
#[cfg(feature = "builtins")]
1414
use crate::builtins::{AsmSlice, AsmStr};
1515

16-
/// A non-zero pointer type, where optional types
17-
/// are guaranteed to use the nullable representation
16+
/// A type which is never zero, and where optional types
17+
/// are guaranteed to use the null-pointer representation
1818
///
1919
/// If `T: SimpleNonZeroPointer` -> `sizeof(Option<T>) == sizeof(T) && repr(Option<T>) == repr(T)`
20-
pub unsafe trait SimpleNonZeroPointer: StaticReflect {}
20+
pub unsafe trait SimpleNonZeroRepr: StaticReflect {}
2121

2222
/// An integer size, named in the style of C/Java
2323
///

0 commit comments

Comments
 (0)