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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use std::path::{Path, PathBuf};
use anyhow::{bail, Result};
pub const REFERENCE_TEMPLATE_FILENAME: &str = "references.md";
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum SourcePackageLayout {
    Sources,
    Specifications,
    Tests,
    Scripts,
    Examples,
    Manifest,
    DocTemplates,
}
impl SourcePackageLayout {
    
    
    
    
    
    
    
    
    
    pub fn path(&self) -> &Path {
        Path::new(self.location_str())
    }
    pub fn try_find_root(starting_path: &Path) -> Result<PathBuf> {
        let mut current_path = starting_path.to_path_buf();
        loop {
            if current_path.join(Self::Manifest.path()).is_file() {
                break Ok(current_path);
            }
            if !current_path.pop() {
                bail!(
                    "Unable to find package manifest in '{}' or in its parents",
                    starting_path.to_string_lossy()
                )
            }
        }
    }
    pub fn location_str(&self) -> &'static str {
        match self {
            Self::Sources => "sources",
            Self::Manifest => "Move.toml",
            Self::Tests => "tests",
            Self::Scripts => "scripts",
            Self::Examples => "examples",
            Self::Specifications => "specifications",
            Self::DocTemplates => "doc_templates",
        }
    }
    pub fn is_optional(&self) -> bool {
        match self {
            Self::Sources | Self::Manifest => false,
            Self::Tests
            | Self::Scripts
            | Self::Examples
            | Self::Specifications
            | Self::DocTemplates => true,
        }
    }
}