• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use std::fmt;
2 use std::fmt::Formatter;
3 
4 use crate::gen::rust::ident::RustIdent;
5 use crate::gen::rust::keywords::parse_rust_keyword;
6 
7 #[derive(Clone, Debug, PartialEq, Eq, Hash)]
8 pub(crate) enum RustPathComponent {
9     Ident(RustIdent),
10     Keyword(&'static str),
11 }
12 
13 impl fmt::Display for RustPathComponent {
fmt(&self, f: &mut Formatter<'_>) -> fmt::Result14     fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
15         match self {
16             RustPathComponent::Ident(ident) => write!(f, "{}", ident),
17             RustPathComponent::Keyword(keyword) => write!(f, "{}", keyword),
18         }
19     }
20 }
21 
22 impl RustPathComponent {
23     pub(crate) const SUPER: RustPathComponent = RustPathComponent::Keyword("super");
24 
parse(s: &str) -> RustPathComponent25     pub(crate) fn parse(s: &str) -> RustPathComponent {
26         if s.starts_with("r#") {
27             RustPathComponent::Ident(RustIdent::new(&s[2..]))
28         } else if let Some(kw) = parse_rust_keyword(s) {
29             RustPathComponent::Keyword(kw)
30         } else {
31             RustPathComponent::Ident(RustIdent::new(s))
32         }
33     }
34 }
35