#![cfg(feature = "backends")]
use core::ptr::NonNull;
#[derive(Debug)]
#[repr(transparent)]
pub struct InternedStr {
ptr: NonNull<str>,
}
impl InternedStr {
#[inline]
pub fn new(val: &str) -> Self {
InternedStr {
ptr: NonNull::from(val),
}
}
#[inline]
pub(super) fn as_str(&self) -> &str {
unsafe { self.ptr.as_ref() }
}
}
impl Eq for InternedStr {}
impl PartialEq for InternedStr {
#[inline]
fn eq(&self, other: &Self) -> bool {
self.as_str() == other.as_str()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn size_of() {
use core::mem;
assert_eq!(mem::size_of::<InternedStr>(), mem::size_of::<&str>());
}
}