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 344151f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Expand Up @@ -139,6 +139,16 @@ pub struct Metadata {
__do_not_match_exhaustively: (),
}

impl Metadata {
/// Get the root package of this metadata instance.
pub fn root_package(&self) -> Option<&Package> {
self.resolve
.as_ref()
.and_then(|res| res.root.as_ref())
.and_then(|root| 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 344151f

Please sign in to comment.