-use std::fmt;
use std::sync::RwLock;
use std::collections::HashSet;
use std::slice;
use std::str;
use std::mem;
use std::cmp::Ordering;
+use std::ops::Deref;
pub fn leek(s: String) -> &'static str {
let boxed = s.into_boxed_str();
cache.insert(s);
InternedString { ptr: s.as_ptr(), len: s.len() }
}
- pub fn to_inner(&self) -> &'static str {
+}
+
+impl Deref for InternedString {
+ type Target = str;
+
+ fn deref(&self) -> &'static str {
unsafe {
let slice = slice::from_raw_parts(self.ptr, self.len);
- str::from_utf8_unchecked(slice)
+ &str::from_utf8_unchecked(slice)
}
}
}
-impl fmt::Debug for InternedString {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "InternedString {{ {} }}", self.to_inner())
- }
-}
-
impl Ord for InternedString {
fn cmp(&self, other: &InternedString) -> Ordering {
- self.to_inner().cmp(&other.to_inner())
+ let str: &str = &*self;
+ str.cmp(&*other)
}
}
metadata: BTreeMap::new(),
replacements: cx.resolve_replacements(),
features: cx.resolve_features.iter().map(|(k, v)| {
- (k.clone(), v.iter().map(|x| x.to_inner().to_string()).collect())
+ (k.clone(), v.iter().map(|x| x.to_string()).collect())
}).collect(),
unused_patches: Vec::new(),
};