1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use syntax::ast;
use syntax::parse::token;

//////////////////////////////////////////////////////////////////////////////

pub trait ToName {
    fn to_name(&self) -> ast::Name;
}

impl ToName for ast::Name {
    fn to_name(&self) -> ast::Name {
        *self
    }
}

impl<'a> ToName for &'a str {
    fn to_name(&self) -> ast::Name {
        token::intern(*self)
    }
}

impl<'a, T> ToName for &'a T where T: ToName {
    fn to_name(&self) -> ast::Name {
        (**self).to_name()
    }
}

impl<'a, T> ToName for &'a mut T where T: ToName {
    fn to_name(&self) -> ast::Name {
        (**self).to_name()
    }
}