Skip to content

Commit

Permalink
Merge pull request #262 from MarijnS95/resolve-index-by-package-id
Browse files Browse the repository at this point in the history
Implement `ops::Index` with `PackageId` for `Resolve` graph
  • Loading branch information
oli-obk authored Jun 13, 2024
2 parents 0fc19a6 + e4b1243 commit 9cf9539
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl Metadata {
impl<'a> std::ops::Index<&'a PackageId> for Metadata {
type Output = Package;

fn index(&self, idx: &'a PackageId) -> &Package {
fn index(&self, idx: &'a PackageId) -> &Self::Output {
self.packages
.iter()
.find(|p| p.id == *idx)
Expand Down Expand Up @@ -272,6 +272,17 @@ pub struct Resolve {
pub root: Option<PackageId>,
}

impl<'a> std::ops::Index<&'a PackageId> for Resolve {
type Output = Node;

fn index(&self, idx: &'a PackageId) -> &Self::Output {
self.nodes
.iter()
.find(|p| p.id == *idx)
.unwrap_or_else(|| panic!("no Node with this id: {:?}", idx))
}
}

#[derive(Clone, Serialize, Deserialize, Debug)]
#[cfg_attr(feature = "builder", derive(Builder))]
#[non_exhaustive]
Expand Down

0 comments on commit 9cf9539

Please sign in to comment.