David Tolnay | 5533772 | 2016-09-11 12:58:56 -0700 | [diff] [blame] | 1 | use Ident; |
| 2 | |
| 3 | pub trait ToIdent { |
| 4 | fn to_ident(&self) -> Ident; |
| 5 | } |
| 6 | |
| 7 | impl ToIdent for Ident { |
| 8 | fn to_ident(&self) -> Ident { |
| 9 | self.clone() |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | impl<'a> ToIdent for &'a str { |
| 14 | fn to_ident(&self) -> Ident { |
| 15 | (**self).into() |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | impl ToIdent for String { |
| 20 | fn to_ident(&self) -> Ident { |
| 21 | self.clone().into() |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | impl<'a, T> ToIdent for &'a T where T: ToIdent { |
| 26 | fn to_ident(&self) -> Ident { |
| 27 | (**self).to_ident() |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | impl<'a, T> ToIdent for &'a mut T where T: ToIdent { |
| 32 | fn to_ident(&self) -> Ident { |
| 33 | (**self).to_ident() |
| 34 | } |
| 35 | } |