Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Metadata.root_package convenience method. #129

Merged
merged 1 commit into from Sep 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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