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;