phantom_type/
lib.rs

1#![deny(warnings)]
2#![doc(test(attr(deny(warnings))))]
3#![doc(test(attr(allow(dead_code))))]
4#![doc(test(attr(allow(unused_variables))))]
5
6#![cfg_attr(not(feature="std"), no_std)]
7
8//! ## Feature flags
9#![doc=document_features::document_features!()]
10
11#[cfg(feature="std")]
12extern crate core;
13
14use core::marker::PhantomData;
15use educe::Educe;
16#[cfg(feature="std")]
17use std::panic::{UnwindSafe, RefUnwindSafe};
18
19/// A [`PhantomData`] analog which prevents "parameter is never used" error,
20/// but does not produce any restrictions in contrast with `PhantomData`.
21#[derive(Educe)]
22#[educe(Clone, Copy, Eq, Ord, PartialEq, PartialOrd, Hash, Default, Debug)]
23pub struct PhantomType<T: ?Sized>(PhantomData<T>);
24
25impl<T: ?Sized> PhantomType<T> {
26    /// Creates `PhantomType` instance.
27    pub const fn new() -> Self { PhantomType(PhantomData) }
28}
29
30unsafe impl<T: ?Sized> Send for PhantomType<T> { }
31unsafe impl<T: ?Sized> Sync for PhantomType<T> { }
32impl<T: ?Sized> Unpin for PhantomType<T> { }
33
34#[cfg(feature="std")]
35impl<T: ?Sized> RefUnwindSafe for PhantomType<T> { }
36
37#[cfg(feature="std")]
38impl<T: ?Sized> UnwindSafe for PhantomType<T> { }