From 344151fa2b83955de9164716ecafd43fbdd3c6e6 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 40643a5a..3deb93f1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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;