blob: 501dd6180ecd8121eb4fba9dc09aeeb5cb9d0961 [file] [log] [blame]
David Tolnayb247df12020-11-27 12:06:12 -08001use proc_macro2::{Ident, Span};
2
3#[derive(Copy, Clone)]
4pub struct Derive {
5 pub what: Trait,
6 pub span: Span,
7}
David Tolnay64703b42020-05-10 22:12:33 -07008
9#[derive(Copy, Clone, PartialEq)]
David Tolnayb247df12020-11-27 12:06:12 -080010pub enum Trait {
David Tolnay64703b42020-05-10 22:12:33 -070011 Clone,
12 Copy,
13}
14
15impl Derive {
16 pub fn from(ident: &Ident) -> Option<Self> {
David Tolnayb247df12020-11-27 12:06:12 -080017 let what = match ident.to_string().as_str() {
18 "Clone" => Trait::Clone,
19 "Copy" => Trait::Copy,
20 _ => return None,
21 };
22 let span = ident.span();
23 Some(Derive { what, span })
24 }
25}
26
27impl PartialEq<Trait> for Derive {
28 fn eq(&self, other: &Trait) -> bool {
29 self.what == *other
David Tolnay64703b42020-05-10 22:12:33 -070030 }
31}