pub fn new(metadata: &Metadata) -> Self {
    let root_resolve_node = {
      let root_resolve_node_opt = {
        let root_id = &metadata.resolve.root;
        metadata
          .resolve
          .nodes
          .iter()
          .find(|node| &node.id == root_id)
      };

      if root_resolve_node_opt.is_none() {
        eprintln!("Resolve was: {:#?}", metadata.resolve);
        eprintln!("root_id: {:?}", metadata.resolve.root);
        panic!("Resolve did not contain root crate!");
      }

      // UNWRAP: Guarded above
      root_resolve_node_opt.unwrap()
    };

    let root_direct_deps = root_resolve_node
      .dependencies
      .iter()
      .cloned()
      .collect::<HashSet<_>>();
    let workspace_crates = metadata
      .workspace_members
      .iter()
      .cloned()
      .collect::<HashSet<_>>();

    let entries = metadata
      .packages
      .iter()
      .map(|package| {
        CrateCatalogEntry::new(
          package,
          root_resolve_node.id == package.id,
          root_direct_deps.contains(&package.id),
          workspace_crates.contains(&package.id),
        )
      })
      .collect::<Vec<_>>();

    let mut package_id_to_entries_idx = HashMap::new();

    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);
    }

    Self {
      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) -> Self {
    let root_resolve_node = {
      let root_resolve_node_opt = {
        let root_id = &metadata.resolve.root;
        metadata
          .resolve
          .nodes
          .iter()
          .find(|node| &node.id == root_id)
      };
      if root_resolve_node_opt.is_none() {
        eprintln!("Resolve was: {:#?}", metadata.resolve);
        eprintln!("root_id: {:?}", metadata.resolve.root);
        panic!("Resolve did not contain root crate!");
      }
      // UNWRAP: Guarded above
      root_resolve_node_opt.unwrap()
    };
    let root_direct_deps = root_resolve_node
      .dependencies
      .iter()
      .cloned()
      .collect::<HashSet<_>>();
    let workspace_crates = metadata
      .workspace_members
      .iter()
      .cloned()
      .collect::<HashSet<_>>();
    let entries = metadata
      .packages
      .iter()
      .map(|package| {
        CrateCatalogEntry::new(
          package,
          root_resolve_node.id == package.id,
          root_direct_deps.contains(&package.id),
          workspace_crates.contains(&package.id),
        )
      })
      .collect::<Vec<_>>();
    let mut package_id_to_entries_idx = HashMap::new();
    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);
    }
    Self {
      entries,
      package_id_to_entries_idx,
    }
  }
pub fn new ( metadata : & Metadata ) -> Self { let root_resolve_node = { let root_resolve_node_opt = { let root_id = & metadata . resolve . root ; metadata . resolve . nodes . iter ( ) . find ( | node | & node . id == root_id ) } ; if root_resolve_node_opt . is_none ( ) { eprintln ! ( " " metadata resolve ) ; eprintln ! ( " " metadata resolve root ) ; panic ! ( " " ) ; } // UNWRAP: Guarded above root_resolve_node_opt . unwrap ( ) } ; let root_direct_deps = root_resolve_node . dependencies . iter ( ) . cloned ( ) . collect :: < HashSet < _ > > ( ) ; let workspace_crates = metadata . workspace_members . iter ( ) . cloned ( ) . collect :: < HashSet < _ > > ( ) ; let entries = metadata . packages . iter ( ) . map ( | package | { CrateCatalogEntry :: new ( package , root_resolve_node . id == package . id , root_direct_deps . contains ( & package . id ) , workspace_crates . contains ( & package . id ) , ) } ) . collect :: < Vec < _ > > ( ) ; let mut package_id_to_entries_idx = HashMap :: new ( ) ; 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 ) ; } Self { 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