Skip to content

Commit

Permalink
Add the Metadata.root_package convenience method.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedodd committed Sep 24, 2020
1 parent f66b1fe commit 80fd07e
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 80fd07e

Please sign in to comment.