]> git.proxmox.com Git - rustc.git/blob - src/vendor/quote/src/ident.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / vendor / quote / src / ident.rs
1 use {Tokens, ToTokens};
2 use std::borrow::Cow;
3 use std::fmt;
4
5 /// An identifier that should be interpolated without quotes.
6 #[derive(Debug, Clone, Eq, Hash)]
7 pub struct Ident(String);
8
9 impl Ident {
10 pub fn new<T: Into<Ident>>(t: T) -> Self {
11 t.into()
12 }
13 }
14
15 impl<'a> From<&'a str> for Ident {
16 fn from(s: &str) -> Self {
17 Ident(s.to_owned())
18 }
19 }
20
21 impl<'a> From<Cow<'a, str>> for Ident {
22 fn from(s: Cow<'a, str>) -> Self {
23 Ident(s.into_owned())
24 }
25 }
26
27 impl From<String> for Ident {
28 fn from(s: String) -> Self {
29 Ident(s)
30 }
31 }
32
33 impl AsRef<str> for Ident {
34 fn as_ref(&self) -> &str {
35 &self.0
36 }
37 }
38
39 impl fmt::Display for Ident {
40 fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> {
41 self.0.fmt(formatter)
42 }
43 }
44
45 impl<T: ?Sized> PartialEq<T> for Ident
46 where T: AsRef<str>
47 {
48 fn eq(&self, other: &T) -> bool {
49 self.0 == other.as_ref()
50 }
51 }
52
53 impl ToTokens for Ident {
54 fn to_tokens(&self, tokens: &mut Tokens) {
55 tokens.append(self.as_ref())
56 }
57 }