workspacer_metadata/
metadata.rs1crate::ix!();
3
4#[async_trait]
6pub trait GetCargoMetadata {
7 type Error;
8 async fn get_cargo_metadata(&self) -> Result<Metadata, Self::Error>;
9}
10
11#[async_trait]
13impl<P,H> GetCargoMetadata for Workspace<P,H>
14where
15 H: CrateHandleInterface<P>,
16 for<'async_trait> P: From<PathBuf> + AsRef<Path> + Send + Sync + 'async_trait,
17{
18 type Error = WorkspaceError;
19
20 async fn get_cargo_metadata(&self) -> Result<Metadata, Self::Error> {
22 let path = self.as_ref().to_path_buf();
23
24 let metadata = tokio::task::spawn_blocking(move || {
26 MetadataCommand::new()
27 .current_dir(&path)
28 .exec()
29 .map_err(|e| CargoMetadataError::MetadataError { error: e.into() })
30 })
31 .await
32 .map_err(|e| WorkspaceError::TokioError(TokioError::JoinError { join_error: e.into() }))??;
33
34 Ok(metadata)
35 }
36}
37
38#[async_trait]
43impl GetCargoMetadata for CrateHandle {
44 type Error = CrateError;
45
46 async fn get_cargo_metadata(&self) -> Result<Metadata, Self::Error> {
47 let cargo_toml_arc = self.cargo_toml_direct();
49 let cargo_toml_guard = cargo_toml_arc.lock().await;
50 let cargo_toml_path = cargo_toml_guard.as_ref().to_path_buf(); let cargo_toml_path2 = cargo_toml_path.clone();
55
56 let metadata = tokio::task::spawn_blocking(move || {
58 let mut cmd = MetadataCommand::new();
59 cmd.manifest_path(cargo_toml_path2);
60 cmd.exec().map_err(|e| CargoMetadataError::MetadataError { error: e.into() })
61 })
62 .await??; Ok(metadata)
65 }
66}