use std::{borrow::Borrow, ptr::NonNull};
#[derive(Debug, Clone)]
pub(super) struct InternedStr {
ptr: NonNull<str>,
}
impl InternedStr {
#[inline]
pub(super) unsafe fn new(ptr: NonNull<str>) -> Self {
Self { ptr }
}
#[inline]
pub(super) unsafe fn as_str(&self) -> &str {
unsafe { self.ptr.as_ref() }
}
}
impl std::hash::Hash for InternedStr {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
unsafe {
self.as_str().hash(state);
}
}
}
impl Eq for InternedStr {}
impl PartialEq for InternedStr {
fn eq(&self, other: &Self) -> bool {
unsafe { self.as_str() == other.as_str() }
}
}
impl Borrow<str> for InternedStr {
fn borrow(&self) -> &str {
unsafe { self.as_str() }
}
}