Rollup merge of #44223 - eddyb:symbol-from-str, r=jseyfried

Implement From<&str> for Symbol.

This lets us have `fn foo<S: Into<Symbol>>` bounds and accept both `&str` and existing `Symbol`s.

r? @jseyfried
This commit is contained in:
Mark Simulacrum 2017-08-31 18:07:47 -06:00 committed by GitHub
commit 9c4bdd3b87

View File

@ -115,6 +115,12 @@ pub fn as_u32(self) -> u32 {
}
}
impl<'a> From<&'a str> for Symbol {
fn from(string: &'a str) -> Symbol {
Symbol::intern(string)
}
}
impl fmt::Debug for Symbol {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}({})", self, self.0)