fn find_root_file(package_name: Option<&str>) -> Result<(String, PathBuf)> {
    let metadata = cargo_metadata::MetadataCommand::new().exec()?;
    let mut root_files = Vec::new();
    for package in metadata.packages {
        if metadata.workspace_members.contains(&package.id) {
            if let Some(target) = package
                .targets
                .into_iter()
                .find(|target| target.kind.iter().any(|kind| kind == "cdylib"))
            {
                root_files.push((package.name, target.src_path.into()))
            }
        }
    }

    if let Some(package_name) = package_name {
        match root_files
            .into_iter()
            .find(|(name, _)| name == package_name)
        {
            Some((_, root_file)) => Ok((package_name.to_string(), root_file)),
            None => Err(Error::NoMatchingCrate(package_name.to_string())),
        }
    } else {
        if root_files.len() > 1 {
            return Err(Error::MultipleCandidateCrate(
                root_files.into_iter().map(|(name, _)| name).collect(),
            ));
        }
        if let Some((name, root_file)) = root_files.pop() {
            Ok((name, root_file))
        } else {
            Err(Error::NoCandidateCrate)
        }
    }
}
/// Returns the name of the crate and the root file.
Returns the name of the crate and the root file.
Returns the name of the crate and the root file .
fn find_root_file(package_name: Option<&str>) -> Result<(String, PathBuf)> {
    let metadata = cargo_metadata::MetadataCommand::new().exec()?;
    let mut root_files = Vec::new();
    for package in metadata.packages {
        if metadata.workspace_members.contains(&package.id) {
            if let Some(target) = package
                .targets
                .into_iter()
                .find(|target| target.kind.iter().any(|kind| kind == "cdylib"))
            {
                root_files.push((package.name, target.src_path.into()))
            }
        }
    }
    if let Some(package_name) = package_name {
        match root_files
            .into_iter()
            .find(|(name, _)| name == package_name)
        {
            Some((_, root_file)) => Ok((package_name.to_string(), root_file)),
            None => Err(Error::NoMatchingCrate(package_name.to_string())),
        }
    } else {
        if root_files.len() > 1 {
            return Err(Error::MultipleCandidateCrate(
                root_files.into_iter().map(|(name, _)| name).collect(),
            ));
        }
        if let Some((name, root_file)) = root_files.pop() {
            Ok((name, root_file))
        } else {
            Err(Error::NoCandidateCrate)
        }
    }
}
fn find_root_file ( package_name : Option < & str > ) -> Result < ( String , PathBuf ) > { let metadata = cargo_metadata :: MetadataCommand :: new ( ) . exec ( ) ? ; let mut root_files = Vec :: new ( ) ; for package in metadata . packages { if metadata . workspace_members . contains ( & package . id ) { if let Some ( target ) = package . targets . into_iter ( ) . find ( | target | target . kind . iter ( ) . any ( | kind | kind == " " ) ) { root_files . push ( ( package . name , target . src_path . into ( ) ) ) } } } if let Some ( package_name ) = package_name { match root_files . into_iter ( ) . find ( | ( name , _ ) | name == package_name ) { Some ( ( _ , root_file ) ) => Ok ( ( package_name . to_string ( ) , root_file ) ) , None => Err ( Error :: NoMatchingCrate ( package_name . to_string ( ) ) ) , } } else { if root_files . len ( ) > 1 { return Err ( Error :: MultipleCandidateCrate ( root_files . into_iter ( ) . map ( | ( name , _ ) | name ) . collect ( ) , ) ) ; } if let Some ( ( name , root_file ) ) = root_files . pop ( ) { Ok ( ( name , root_file ) ) } else { Err ( Error :: NoCandidateCrate ) } } }
Returns the name of the crate and the root file.
Returns the name of the crate and the root file .
package_name
Option<&str>
package_name
Option<&str>