• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use crate::intern::{self, InternedString};
2 use std::path::Path;
3 
4 pub trait InternedVec<T>
5 where
6     T: ?Sized,
7 {
vec(&self) -> Vec<&'static T>8     fn vec(&self) -> Vec<&'static T>;
9 }
10 
11 impl<T> InternedVec<T> for Vec<InternedString>
12 where
13     T: ?Sized + Element,
14 {
vec(&self) -> Vec<&'static T>15     fn vec(&self) -> Vec<&'static T> {
16         self.iter().copied().map(Element::unintern).collect()
17     }
18 }
19 
intern<T>(elements: &[&T]) -> Vec<InternedString> where T: ?Sized + Element,20 pub fn intern<T>(elements: &[&T]) -> Vec<InternedString>
21 where
22     T: ?Sized + Element,
23 {
24     elements.iter().copied().map(Element::intern).collect()
25 }
26 
27 pub trait Element {
intern(&self) -> InternedString28     fn intern(&self) -> InternedString;
unintern(_: InternedString) -> &'static Self29     fn unintern(_: InternedString) -> &'static Self;
30 }
31 
32 impl Element for str {
intern(&self) -> InternedString33     fn intern(&self) -> InternedString {
34         intern::intern(self)
35     }
36 
unintern(interned: InternedString) -> &'static Self37     fn unintern(interned: InternedString) -> &'static Self {
38         interned.str()
39     }
40 }
41 
42 impl Element for Path {
intern(&self) -> InternedString43     fn intern(&self) -> InternedString {
44         intern::intern(&self.to_string_lossy())
45     }
46 
unintern(interned: InternedString) -> &'static Self47     fn unintern(interned: InternedString) -> &'static Self {
48         Path::new(interned.str())
49     }
50 }
51