rust_code_analysis/
traits.rs1use std::path::Path;
2use std::sync::Arc;
3use tree_sitter::Language;
4
5use crate::abc::Abc;
6use crate::alterator::Alterator;
7use crate::checker::Checker;
8use crate::cognitive::Cognitive;
9use crate::cyclomatic::Cyclomatic;
10use crate::exit::Exit;
11use crate::getter::Getter;
12use crate::halstead::Halstead;
13use crate::langs::*;
14use crate::loc::Loc;
15use crate::mi::Mi;
16use crate::nargs::NArgs;
17use crate::node::Node;
18use crate::nom::Nom;
19use crate::npa::Npa;
20use crate::npm::Npm;
21use crate::parser::Filter;
22use crate::preproc::PreprocResults;
23use crate::wmc::Wmc;
24
25pub trait Callback {
30 type Res;
32 type Cfg;
34
35 fn call<T: ParserTrait>(cfg: Self::Cfg, parser: &T) -> Self::Res;
37}
38
39#[doc(hidden)]
40pub trait CodeMetricsT:
41 Cognitive + Cyclomatic + Exit + Halstead + NArgs + Loc + Nom + Mi + Wmc + Abc + Npm + Npa
42{
43}
44
45#[doc(hidden)]
46pub trait TSLanguage {
47 type BaseLang;
48
49 fn get_lang() -> LANG;
50 fn get_language() -> Language;
51 fn get_lang_name() -> &'static str;
52}
53
54#[doc(hidden)]
55pub trait ParserTrait {
56 type Checker: Alterator + Checker;
57 type Getter: Getter;
58 type Cognitive: Cognitive;
59 type Cyclomatic: Cyclomatic;
60 type Halstead: Halstead;
61 type Loc: Loc;
62 type Nom: Nom;
63 type Mi: Mi;
64 type NArgs: NArgs;
65 type Exit: Exit;
66 type Wmc: Wmc;
67 type Abc: Abc;
68 type Npm: Npm;
69 type Npa: Npa;
70
71 fn new(code: Vec<u8>, path: &Path, pr: Option<Arc<PreprocResults>>) -> Self;
72 fn get_language(&self) -> LANG;
73 fn get_root(&self) -> Node;
74 fn get_code(&self) -> &[u8];
75 fn get_filters(&self, filters: &[String]) -> Filter;
76}
77
78pub(crate) trait Search<'a> {
79 fn first_occurence(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
80 fn act_on_node(&self, pred: &mut dyn FnMut(&Node<'a>));
81 fn first_child(&self, pred: fn(u16) -> bool) -> Option<Node<'a>>;
82 fn act_on_child(&self, action: &mut dyn FnMut(&Node<'a>));
83}