pub fn expand(&self, package: impl AsRef<str>) -> anyhow::Result<String> {
        let package = package.as_ref();
        let pkg = self.find_package(package)?;

        let manifest_path = pkg.manifest_path.to_string();

        // try to run cargo if it fails due to virtual manifest
        match self.run_cargo(manifest_path) {
            res @ Ok(_) => res,
            Err(err) => {
                match err.downcast::<MissingWorkspace>() {
                    Ok(_) => {
                        // need to make a copy for registry packages due to virtual manifests
                        let tmp =
                            tempdir::TempDir::new(&format!("dep-expand-{}", pkg.name)).unwrap();
                        let dep_path = pkg
                            .manifest_path
                            .parent()
                            .context("Failed to find dependency dir")?;
                        let package_dir = dep_path.file_name().unwrap();
                        let tmp_package_dir = tmp.path().join(package_dir);

                        // copy the package to temp location
                        fs_extra::dir::copy(
                            dep_path,
                            tmp.path(),
                            &fs_extra::dir::CopyOptions::default(),
                        )?;

                        // try run again but on the copy
                        self.run_cargo(tmp_package_dir.join("Cargo.toml"))
                    }
                    Err(err) => Err(err),
                }
            }
        }
    }
/// Returns the expanded lib of the given dependency.
// Based on https://github.com/rsolomo/cargo-check
Returns the expanded lib of the given dependency.
Returns the expanded lib of the given dependency .
pub fn expand(&self, package: impl AsRef<str>) -> anyhow::Result<String> {
        let package = package.as_ref();
        let pkg = self.find_package(package)?;
        let manifest_path = pkg.manifest_path.to_string();
        // try to run cargo if it fails due to virtual manifest
        match self.run_cargo(manifest_path) {
            res @ Ok(_) => res,
            Err(err) => {
                match err.downcast::<MissingWorkspace>() {
                    Ok(_) => {
                        // need to make a copy for registry packages due to virtual manifests
                        let tmp =
                            tempdir::TempDir::new(&format!("dep-expand-{}", pkg.name)).unwrap();
                        let dep_path = pkg
                            .manifest_path
                            .parent()
                            .context("Failed to find dependency dir")?;
                        let package_dir = dep_path.file_name().unwrap();
                        let tmp_package_dir = tmp.path().join(package_dir);
                        // copy the package to temp location
                        fs_extra::dir::copy(
                            dep_path,
                            tmp.path(),
                            &fs_extra::dir::CopyOptions::default(),
                        )?;
                        // try run again but on the copy
                        self.run_cargo(tmp_package_dir.join("Cargo.toml"))
                    }
                    Err(err) => Err(err),
                }
            }
        }
    }
pub fn expand ( & self , package : impl AsRef < str > ) -> anyhow :: Result < String > { let package = package . as_ref ( ) ; let pkg = self . find_package ( package ) ? ; let manifest_path = pkg . manifest_path . to_string ( ) ; // try to run cargo if it fails due to virtual manifest match self . run_cargo ( manifest_path ) { res @ Ok ( _ ) => res , Err ( err ) => { match err . downcast :: < MissingWorkspace > ( ) { Ok ( _ ) => { // need to make a copy for registry packages due to virtual manifests let tmp = tempdir :: TempDir :: new ( & format ! ( " " pkg name ) ) . unwrap ( ) ; let dep_path = pkg . manifest_path . parent ( ) . context ( " " ) ? ; let package_dir = dep_path . file_name ( ) . unwrap ( ) ; let tmp_package_dir = tmp . path ( ) . join ( package_dir ) ; // copy the package to temp location fs_extra :: dir :: copy ( dep_path , tmp . path ( ) , & fs_extra :: dir :: CopyOptions :: default ( ) , ) ? ; // try run again but on the copy self . run_cargo ( tmp_package_dir . join ( " " ) ) } Err ( err ) => Err ( err ) , } } } }
Returns the expanded lib of the given dependency.
Returns the expanded lib of the given dependency .
&self
package
impl AsRef<str>