Skip to content

Commit

Permalink
Merge pull request #129 from thedodd/126-root-package-method
Browse files Browse the repository at this point in the history
Add the Metadata.root_package convenience method.
  • Loading branch information
oli-obk committed Sep 24, 2020
2 parents f66b1fe + 80fd07e commit 477930d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lib.rs
Expand Up @@ -139,6 +139,14 @@ pub struct Metadata {
__do_not_match_exhaustively: (),
}

impl Metadata {
/// Get the root package of this metadata instance.
pub fn root_package(&self) -> Option<&Package> {
let root = self.resolve.as_ref()?.root.as_ref()?;
self.packages.iter().find(|pkg| &pkg.id == root)
}
}

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

Expand Down

0 comments on commit 477930d

Please sign in to comment.