workspacer_workspace/
into_iterator.rs

1// ---------------- [ File: workspacer-workspace/src/into_iterator.rs ]
2crate::ix!();
3
4impl<'a,P,H:CrateHandleInterface<P>> IntoIterator for &'a Workspace<P,H> 
5where for<'async_trait> P: From<PathBuf> + AsRef<Path> + Send + Sync + 'async_trait
6{
7    type Item     = &'a Arc<AsyncMutex<H>>;
8    type IntoIter = Iter<'a, Arc<AsyncMutex<H>>>;
9
10    fn into_iter(self) -> Self::IntoIter {
11        self.crates().iter()
12    }
13}
14
15#[cfg(test)]
16mod test_into_iterator {
17    use super::*;
18
19    #[traced_test]
20    async fn test_real_workspace_into_iterator() {
21        // 1) Create a mock workspace on disk with 2 crates
22        let path = create_mock_workspace(vec![
23            CrateConfig::new("crateA").with_src_files(),
24            CrateConfig::new("crateB").with_src_files(),
25        ]).await.expect("Failed to create mock workspace");
26
27        // 2) Convert path -> Workspace<PathBuf, CrateHandle>
28        let ws = Workspace::<PathBuf, CrateHandle>::new(&path)
29            .await
30            .expect("Should create workspace from path");
31
32        // 3) Now test the into_iterator for &ws
33        let crates_vec: Vec<_> = ws.into_iter().collect();
34        assert_eq!(crates_vec.len(), 2, "Should have 2 crates in iteration");
35    }
36}