use core::{hash::Hash, ptr::NonNull};
#[derive(Debug)]
pub(super) struct InternedStr<Char> {
ptr: NonNull<[Char]>,
}
impl<Char> InternedStr<Char> {
pub(super) const unsafe fn new(ptr: NonNull<[Char]>) -> Self {
Self { ptr }
}
pub(super) unsafe fn as_ref(&self) -> &[Char] {
unsafe { self.ptr.as_ref() }
}
}
impl<Char> Clone for InternedStr<Char> {
fn clone(&self) -> Self {
*self
}
}
impl<Char> Copy for InternedStr<Char> {}
impl<Char> Eq for InternedStr<Char> where Char: Eq {}
impl<Char> PartialEq for InternedStr<Char>
where
Char: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
unsafe { self.as_ref() == other.as_ref() }
}
}
impl<Char> Hash for InternedStr<Char>
where
Char: Hash,
{
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
unsafe {
self.as_ref().hash(state);
}
}
}