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
33
34
35
36
#![allow(dead_code)]
use derive_more::Constructor;
use proc_macro2::TokenStream;
use smol_str::SmolStr;

/// `RustItemPath` represents the path to a Rust item within a module.
#[derive(Constructor, Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct RustItemPath {
  pub parent_module_path: SmolStr,
  pub item_name: SmolStr,
}

impl RustItemPath {
  pub fn get_fully_qualified_name(&self) -> SmolStr {
    if self.parent_module_path.is_empty() {
      SmolStr::new(self.item_name.as_str())
    } else {
      SmolStr::new(format!("{}::{}", self.parent_module_path, self.item_name).as_str())
    }
  }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub(crate) enum RustItemKind {
  ConstVarDecl,
  TraitImpls,
  Any,
}

/// Represents a Rust source item.
#[derive(Constructor)]
pub(crate) struct RustItem {
  pub kind: RustItemKind,
  pub path: RustItemPath,
  pub item: TokenStream,
}