grit_pattern_matcher/
file_owners.rs1use elsa::FrozenVec;
2use grit_util::{Ast, MatchRanges};
3use std::cell::RefCell;
4use std::fmt::{self, Debug};
5use std::ops;
6use std::path::PathBuf;
7
8pub struct FileOwners<Tree: Ast>(FrozenVec<Box<FileOwner<Tree>>>);
9
10impl<Tree: Ast> FileOwners<Tree> {
11 pub fn new() -> Self {
12 Self(FrozenVec::new())
13 }
14
15 pub fn push(&self, file: FileOwner<Tree>) {
16 self.0.push(Box::new(file))
17 }
18}
19
20impl<Tree: Ast> Default for FileOwners<Tree> {
21 fn default() -> Self {
22 Self::new()
23 }
24}
25
26impl<Tree: Ast> ops::Deref for FileOwners<Tree> {
27 type Target = FrozenVec<Box<FileOwner<Tree>>>;
28
29 fn deref(&self) -> &Self::Target {
30 &self.0
31 }
32}
33
34impl<Tree: Ast> Debug for FileOwners<Tree> {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 self.0
37 .iter()
38 .try_fold((), |_, file| writeln!(f, "{}", file.name.display()))
39 }
40}
41
42#[derive(Debug, Clone)]
43pub struct FileOwner<Tree: Ast> {
44 pub absolute_path: PathBuf,
45 pub name: PathBuf,
46 pub tree: Tree,
49 pub matches: RefCell<MatchRanges>,
50 pub new: bool,
51}
52
53impl<Tree: Ast> PartialEq for FileOwner<Tree> {
54 fn eq(&self, other: &Self) -> bool {
55 self.name == other.name && self.tree == other.tree
56 }
57}