1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#![deny(warnings)]
#![cfg_attr(not(feature="std"), no_std)]

//! **Crate features**
//!
//! * `"std"`
//! Enabled by default. Disable to make the library `#![no_std]`.

#[cfg(feature="std")]
extern crate core;

use core::marker::PhantomData;
use educe::Educe;
#[cfg(feature="std")]
use std::panic::{UnwindSafe, RefUnwindSafe};

/// A [`PhantomData`](core::marker::PhantomData) analog which prevents "parameter is never used" error,
/// but does not produce any restrictions in contrast with `PhantomData`.
#[derive(Educe)]
#[educe(Clone, Copy, Eq, Ord, PartialEq, PartialOrd, Hash, Default, Debug)]
pub struct PhantomType<T: ?Sized>(PhantomData<T>);

impl<T: ?Sized> PhantomType<T> {
    /// Creates `PhantomType` instance.
    pub const fn new() -> Self { PhantomType(PhantomData) }
}

unsafe impl<T: ?Sized> Send for PhantomType<T> { }
unsafe impl<T: ?Sized> Sync for PhantomType<T> { }
impl<T: ?Sized> Unpin for PhantomType<T> { }

#[cfg(feature="std")]
impl<T: ?Sized> RefUnwindSafe for PhantomType<T> { }

#[cfg(feature="std")]
impl<T: ?Sized> UnwindSafe for PhantomType<T> { }