1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use core::ptr::NonNull;
#[derive(Debug, Copy, Clone)]
#[repr(transparent)]
pub struct InternedStr {
ptr: NonNull<str>,
}
impl InternedStr {
#[inline]
pub fn new(val: &str) -> Self {
InternedStr {
ptr: NonNull::from(val),
}
}
#[inline]
pub(crate) unsafe fn as_str(&self) -> &str {
self.ptr.as_ref()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn size_of() {
use std::mem;
assert_eq!(mem::size_of::<InternedStr>(), mem::size_of::<&str>());
}
}