Skip to main content

windjammer_runtime/
marker.rs

1// Marker Types Module
2//
3// Provides zero-cost marker types for compile-time type tracking.
4// These types have no runtime representation but enable powerful
5// type-level programming patterns.
6
7use std::marker::PhantomData as StdPhantomData;
8
9/// Zero-sized type used to mark things that "act like" they own a T.
10///
11/// PhantomData<T> is used to tell the compiler that a type uses T,
12/// even though T never appears in the struct's fields.
13///
14/// Common use cases:
15/// - Generic wrapper types that don't directly store T
16/// - Type-safe handles/IDs that track what they point to
17/// - Zero-cost type-level state machines
18///
19/// # Examples
20///
21/// ```
22/// use windjammer_runtime::marker::PhantomData;
23///
24/// // Type-safe buffer handle
25/// pub struct BufferId<T> {
26///     id: u32,
27///     _phantom: PhantomData<T>,
28/// }
29///
30/// // Compiler knows this BufferId is for CameraUniforms
31/// let camera_buffer: BufferId<CameraUniforms> = BufferId {
32///     id: 42,
33///     _phantom: PhantomData,
34/// };
35/// ```
36#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
37pub struct PhantomData<T: ?Sized>(StdPhantomData<T>);
38
39impl<T: ?Sized> PhantomData<T> {
40    /// Creates a new PhantomData.
41    pub const fn new() -> PhantomData<T> {
42        PhantomData(StdPhantomData)
43    }
44}
45
46// Re-export for convenient use
47pub use self::PhantomData as Phantom;