1use pool::Pool;
2use std::ffi::{CStr, CString, OsStr, OsString};
3use std::path::{Path, PathBuf};
4
5pub trait Intern {
6 type Interned: 'static;
7 fn intern(self) -> &'static Self::Interned;
8}
9
10lazy_static!{
11 static ref STR_POOL: Pool<str> = Pool::new();
12 static ref C_STR_POOL: Pool<CStr> = Pool::new();
13 static ref OS_STR_POOL: Pool<OsStr> = Pool::new();
14 static ref PATH_POOL: Pool<Path> = Pool::new();
15}
16
17impl<'a> Intern for &'a str {
18 type Interned = String;
19 fn intern(self) -> &'static Self::Interned { STR_POOL.intern(self) }
20}
21impl Intern for String {
22 type Interned = Self;
23 fn intern(self) -> &'static Self::Interned { STR_POOL.intern(self) }
24}
25impl<'a> Intern for &'a String {
26 type Interned = String;
27 fn intern(self) -> &'static Self::Interned { STR_POOL.intern(&**self) }
28}
29impl<'a> Intern for &'a mut String {
30 type Interned = String;
31 fn intern(self) -> &'static Self::Interned { STR_POOL.intern(&**self) }
32}
33
34impl<'a> Intern for &'a CStr {
35 type Interned = CString;
36 fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(self) }
37}
38impl Intern for CString {
39 type Interned = Self;
40 fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(self) }
41}
42impl<'a> Intern for &'a CString {
43 type Interned = CString;
44 fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(&**self) }
45}
46impl<'a> Intern for &'a mut CString {
47 type Interned = CString;
48 fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(&**self) }
49}
50
51impl<'a> Intern for &'a OsStr {
52 type Interned = OsString;
53 fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(self) }
54}
55impl Intern for OsString {
56 type Interned = Self;
57 fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(self) }
58}
59impl<'a> Intern for &'a OsString {
60 type Interned = OsString;
61 fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(&**self) }
62}
63impl<'a> Intern for &'a mut OsString {
64 type Interned = OsString;
65 fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(&**self) }
66}
67
68impl<'a> Intern for &'a Path {
69 type Interned = PathBuf;
70 fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(self) }
71}
72impl Intern for PathBuf {
73 type Interned = Self;
74 fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(self) }
75}
76impl<'a> Intern for &'a PathBuf {
77 type Interned = PathBuf;
78 fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(&**self) }
79}
80impl<'a> Intern for &'a mut PathBuf {
81 type Interned = PathBuf;
82 fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(&**self) }
83}