From 80fd07e1952e609167c5b75879ddb4c4c891af20 Mon Sep 17 00:00:00 2001 From: Anthony Dodd Date: Thu, 24 Sep 2020 07:40:00 -0500 Subject: [PATCH] Add the Metadata.root_package convenience method. --- src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 40643a5a..b7a83906 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;