workspacer_interface/
crate_handle_interface.rs

1// ---------------- [ File: workspacer-interface/src/crate_handle_interface.rs ]
2crate::ix!();
3
4pub trait CrateHandleInterface<P>
5: ValidateIntegrity<Error=CrateError>
6+ Send
7+ Sync
8+ PinWildcardDependencies<Error=CrateError>
9+ ReadyForCargoPublish<Error=CrateError>
10+ CheckIfSrcDirectoryContainsValidFiles
11+ CheckIfReadmeExists
12+ GetReadmePath
13+ GetSourceFilesWithExclusions
14+ GetTestFiles
15+ HasTestsDirectory
16+ GetFilesInDirectory
17+ GetFilesInDirectoryWithExclusions
18+ HasCargoToml
19+ AsRef<Path>
20+ AsyncTryFrom<P,Error=CrateError>
21where
22    for<'async_trait> 
23    P
24    : HasCargoTomlPathBuf 
25    + AsRef<Path> 
26    + Send 
27    + Sync
28    + 'async_trait,
29
30    CrateError: From<<P as HasCargoTomlPathBuf>::Error>,
31{}
32
33#[async_trait]
34pub trait GetTestFiles {
35
36    async fn test_files(&self) -> Result<Vec<PathBuf>, CrateError>;
37}
38
39pub trait HasTestsDirectory {
40
41    fn has_tests_directory(&self) -> bool;
42}
43
44pub trait CheckIfReadmeExists {
45
46    fn check_readme_exists(&self) -> Result<(), CrateError>;
47}
48
49#[async_trait]
50pub trait GetReadmePath {
51
52    async fn readme_path(&self) -> Result<Option<PathBuf>, CrateError>;
53}
54
55pub trait HasCargoToml {
56
57    fn cargo_toml<'a>(&'a self) -> &'a dyn CargoTomlInterface;
58}
59
60#[async_trait]
61pub trait HasCargoTomlPathBuf {
62
63    type Error;
64
65    async fn cargo_toml_path_buf(&self) -> Result<PathBuf, Self::Error>;
66}
67
68#[async_trait]
69impl<P> HasCargoTomlPathBuf for P 
70where for <'async_trait> P: AsRef<Path> + Send + Sync + 'async_trait
71{
72    type Error = CrateError;
73
74    /// Asynchronously returns the path to the `Cargo.toml`
75    async fn cargo_toml_path_buf(&self) -> Result<PathBuf, Self::Error> 
76    {
77        let cargo_path = self.as_ref().join("Cargo.toml");
78        if fs::metadata(&cargo_path).await.is_ok() {
79            Ok(cargo_path)
80        } else {
81            Err(CrateError::FileNotFound {
82                missing_file: cargo_path,
83            })
84        }
85    }
86}
87
88pub trait CheckIfSrcDirectoryContainsValidFiles {
89
90    fn check_src_directory_contains_valid_files(&self) -> Result<(), CrateError>;
91}
92
93#[async_trait]
94pub trait GetSourceFilesWithExclusions {
95
96    async fn source_files_excluding(&self, exclude_files: &[&str]) -> Result<Vec<PathBuf>, CrateError>;
97}
98
99#[async_trait]
100pub trait GetFilesInDirectory {
101
102    async fn get_files_in_dir(&self, dir_name: &str, extension: &str) 
103        -> Result<Vec<PathBuf>, CrateError>;
104}
105
106#[async_trait]
107pub trait GetFilesInDirectoryWithExclusions {
108
109    async fn get_files_in_dir_with_exclusions(
110        &self,
111        dir_name: &str,
112        extension: &str,
113        exclude_files: &[&str]
114    ) -> Result<Vec<PathBuf>, CrateError>;
115}
116
117/// Trait for checking if a component is ready for Cargo publishing
118#[async_trait]
119pub trait ReadyForCargoPublish {
120
121    type Error;
122
123    /// Checks if the crate is ready for Cargo publishing
124    async fn ready_for_cargo_publish(&self) -> Result<(), Self::Error>;
125}