string_interner/backend/bucket/
interned_str.rs1#![cfg(feature = "backends")]
2
3use core::ptr::NonNull;
4
5#[derive(Debug)]
10#[repr(transparent)]
11pub struct InternedStr {
12 ptr: NonNull<str>,
13}
14
15impl InternedStr {
16 #[inline]
18 pub fn new(val: &str) -> Self {
19 InternedStr {
20 ptr: NonNull::from(val),
21 }
22 }
23
24 #[inline]
30 pub(super) fn as_str(&self) -> &str {
31 unsafe { self.ptr.as_ref() }
35 }
36}
37
38impl Eq for InternedStr {}
39
40impl PartialEq for InternedStr {
41 #[inline]
42 fn eq(&self, other: &Self) -> bool {
43 self.as_str() == other.as_str()
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn size_of() {
53 use core::mem;
54 assert_eq!(mem::size_of::<InternedStr>(), mem::size_of::<&str>());
55 }
56}