pub fn new(metadata: &Metadata) -> Result<Self> {
    let resolve = metadata
      .resolve
      .as_ref()
      .ok_or_else(|| RazeError::Generic("Missing resolve graph".into()))?;

    let workspace_crates: Vec<&Node> = resolve
      .nodes
      .iter()
      .filter(|node| metadata.workspace_members.contains(&node.id))
      .collect();

    let entries = metadata
      .packages
      .iter()
      .map(|package| {
        CrateCatalogEntry::new(
          package,
          metadata.workspace_members.contains(&package.id),
          workspace_crates
            .iter()
            .filter_map(|node| {
              if node.dependencies.contains(&package.id) {
                Some(node.id.clone())
              } else {
                None
              }
            })
            .collect(),
        )
      })
      .collect::<Vec<_>>();

    let mut package_id_to_entries_idx = HashMap::new();

    // This loop also ensures there are no duplicates
    for (idx, entry) in entries.iter().enumerate() {
      let existing_value = package_id_to_entries_idx.insert(entry.package.id.clone(), idx);
      assert!(None == existing_value);
    }

    Ok(Self {
      metadata: metadata.clone(),
      entries,
      package_id_to_entries_idx,
    })
  }
/// Produces a CrateCatalog using the package entries from a metadata blob.
Produces a CrateCatalog using the package entries from a metadata blob.
Produces a CrateCatalog using the package entries from a metadata blob .
pub fn new(metadata: &Metadata) -> Result<Self> {
    let resolve = metadata
      .resolve
      .as_ref()
      .ok_or_else(|| RazeError::Generic("Missing resolve graph".into()))?;
    let workspace_crates: Vec<&Node> = resolve
      .nodes
      .iter()
      .filter(|node| metadata.workspace_members.contains(&node.id))
      .collect();
    let entries = metadata
      .packages
      .iter()
      .map(|package| {
        CrateCatalogEntry::new(
          package,
          metadata.workspace_members.contains(&package.id),
          workspace_crates
            .iter()
            .filter_map(|node| {
              if node.dependencies.contains(&package.id) {
                Some(node.id.clone())
              } else {
                None
              }
            })
            .collect(),
        )
      })
      .collect::<Vec<_>>();
    let mut package_id_to_entries_idx = HashMap::new();
    // This loop also ensures there are no duplicates
    for (idx, entry) in entries.iter().enumerate() {
      let existing_value = package_id_to_entries_idx.insert(entry.package.id.clone(), idx);
      assert!(None == existing_value);
    }
    Ok(Self {
      metadata: metadata.clone(),
      entries,
      package_id_to_entries_idx,
    })
  }
pub fn new ( metadata : & Metadata ) -> Result < Self > { let resolve = metadata . resolve . as_ref ( ) . ok_or_else ( | | RazeError :: Generic ( " " . into ( ) ) ) ? ; let workspace_crates : Vec < & Node > = resolve . nodes . iter ( ) . filter ( | node | metadata . workspace_members . contains ( & node . id ) ) . collect ( ) ; let entries = metadata . packages . iter ( ) . map ( | package | { CrateCatalogEntry :: new ( package , metadata . workspace_members . contains ( & package . id ) , workspace_crates . iter ( ) . filter_map ( | node | { if node . dependencies . contains ( & package . id ) { Some ( node . id . clone ( ) ) } else { None } } ) . collect ( ) , ) } ) . collect :: < Vec < _ > > ( ) ; let mut package_id_to_entries_idx = HashMap :: new ( ) ; // This loop also ensures there are no duplicates for ( idx , entry ) in entries . iter ( ) . enumerate ( ) { let existing_value = package_id_to_entries_idx . insert ( entry . package . id . clone ( ) , idx ) ; assert ! ( None existing_value ) ; } Ok ( Self { metadata : metadata . clone ( ) , entries , package_id_to_entries_idx , } ) }
Produces a CrateCatalog using the package entries from a metadata blob.
Produces a CrateCatalog using the package entries from a metadata blob .
metadata
&Metadata
metadata
&Metadata