Use symbols when parsing values out of attribute

This commit is contained in:
David Tolnay
2019-07-31 20:59:25 -07:00
parent 97de3dccbb
commit 735e56c26f
2 changed files with 67 additions and 52 deletions
+9 -1
View File
@@ -1,6 +1,8 @@
use std::fmt::{self, Display};
use syn::{Ident, Path};
pub struct Symbol(&'static str);
#[derive(Copy, Clone)]
pub struct Symbol(pub &'static str);
pub const ALIAS: Symbol = Symbol("alias");
pub const BORROW: Symbol = Symbol("borrow");
@@ -51,3 +53,9 @@ impl PartialEq<Symbol> for Path {
self.is_ident(word.0)
}
}
impl Display for Symbol {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(self.0)
}
}