workspacer_workspace/
path_validator.rs

1// ---------------- [ File: workspacer-workspace/src/path_validator.rs ]
2crate::ix!();
3
4#[async_trait]
5impl<P,H:CrateHandleInterface<P>> AsyncPathValidator for Workspace<P,H> 
6where for<'async_trait> P: From<PathBuf> + AsRef<Path> + Send + Sync + 'async_trait
7{
8
9    /// Asynchronously checks if the path is a valid Rust workspace
10    async fn is_valid(path: &Path) -> bool {
11        fs::metadata(path.join("Cargo.toml")).await.is_ok()
12    }
13}
14
15#[cfg(test)]
16mod test_async_path_validator {
17    use super::*;
18
19    // We'll define a local alias for simpler usage
20    type MyWorkspace<P,H> = Workspace<P,H>;
21
22    #[traced_test]
23    async fn test_path_with_cargo_toml_is_valid() {
24        let tmp = tempdir().unwrap();
25        let dir = tmp.path().to_path_buf();
26
27        // Place a Cargo.toml
28        fs::write(dir.join("Cargo.toml"), b"[workspace]\nmembers=[]").await.unwrap();
29
30        let valid = MyWorkspace::<PathBuf,CrateHandle>::is_valid(dir.as_path()).await;
31        assert!(valid, "Directory with a Cargo.toml => is_valid=true");
32    }
33
34    #[traced_test]
35    async fn test_path_without_cargo_toml_is_not_valid() {
36        let tmp = tempdir().unwrap();
37        let dir = tmp.path().to_path_buf();
38
39        let valid = MyWorkspace::<PathBuf,CrateHandle>::is_valid(dir.as_path()).await;
40        assert!(!valid, "No Cargo.toml => is_valid=false");
41    }
42}