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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use pool::Pool;
use std::ffi::{CStr, CString, OsStr, OsString};
use std::path::{Path, PathBuf};

pub trait Intern {
    type Interned: 'static;
    fn intern(self) -> &'static Self::Interned;
}

lazy_static!{
    static ref STR_POOL: Pool<str> = Pool::new();
    static ref C_STR_POOL: Pool<CStr> = Pool::new();
    static ref OS_STR_POOL: Pool<OsStr> = Pool::new();
    static ref PATH_POOL: Pool<Path> = Pool::new();
}

impl<'a> Intern for &'a str {
    type Interned = String;
    fn intern(self) -> &'static Self::Interned { STR_POOL.intern(self) }
}
impl Intern for String {
    type Interned = Self;
    fn intern(self) -> &'static Self::Interned { STR_POOL.intern(self) }
}
impl<'a> Intern for &'a String {
    type Interned = String;
    fn intern(self) -> &'static Self::Interned { STR_POOL.intern(&**self) }
}
impl<'a> Intern for &'a mut String {
    type Interned = String;
    fn intern(self) -> &'static Self::Interned { STR_POOL.intern(&**self) }
}

impl<'a> Intern for &'a CStr {
    type Interned = CString;
    fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(self) }
}
impl Intern for CString {
    type Interned = Self;
    fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(self) }
}
impl<'a> Intern for &'a CString {
    type Interned = CString;
    fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(&**self) }
}
impl<'a> Intern for &'a mut CString {
    type Interned = CString;
    fn intern(self) -> &'static Self::Interned { C_STR_POOL.intern(&**self) }
}

impl<'a> Intern for &'a OsStr {
    type Interned = OsString;
    fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(self) }
}
impl Intern for OsString {
    type Interned = Self;
    fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(self) }
}
impl<'a> Intern for &'a OsString {
    type Interned = OsString;
    fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(&**self) }
}
impl<'a> Intern for &'a mut OsString {
    type Interned = OsString;
    fn intern(self) -> &'static Self::Interned { OS_STR_POOL.intern(&**self) }
}

impl<'a> Intern for &'a Path {
    type Interned = PathBuf;
    fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(self) }
}
impl Intern for PathBuf {
    type Interned = Self;
    fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(self) }
}
impl<'a> Intern for &'a PathBuf {
    type Interned = PathBuf;
    fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(&**self) }
}
impl<'a> Intern for &'a mut PathBuf {
    type Interned = PathBuf;
    fn intern(self) -> &'static Self::Interned { PATH_POOL.intern(&**self) }
}