use std::marker::PhantomData;
use std::fmt;
pub struct ContextKey<T> {
#[doc(hidden)]
pub __name: &'static str,
#[doc(hidden)]
pub __phantom: PhantomData<T>,
}
impl<T> Copy for ContextKey<T> {}
#[cfg_attr(feature = "cargo-clippy", allow(expl_impl_clone_on_copy))]
impl<T> Clone for ContextKey<T> {
fn clone(&self) -> Self {
ContextKey {
__name: self.__name,
__phantom: self.__phantom,
}
}
}
impl<T> fmt::Debug for ContextKey<T> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
write!(fmt, "ContextKey({:?})", self.__name)
}
}
impl<T> ContextKey<T> {
pub fn name(&self) -> &str {
self.__name
}
}
#[macro_export]
macro_rules! context_key {
($name:expr) => {{
$crate::helpers::fabric::ContextKey {
__name: $name,
__phantom: ::std::marker::PhantomData
}
}}
}
#[test]
fn key_is_copy() {
const K: ContextKey<Vec<String>> = context_key!("k");
let x = K;
let y = x;
assert_eq!(x.name(), y.name());
}