mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Add a mean to mutably access the members of a workspace
It is used by cargo-c to patch all the lib crates in a workspace.
This commit is contained in:
parent
ed0c8c6d66
commit
6fe08fa833
@ -473,6 +473,26 @@ impl<'cfg> Workspace<'cfg> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a mutable iterator over all packages in this workspace
|
||||
pub fn members_mut(&mut self) -> impl Iterator<Item = &mut Package> {
|
||||
let packages = &mut self.packages.packages;
|
||||
let members: HashSet<_> = self
|
||||
.members
|
||||
.iter()
|
||||
.map(|path| path.parent().unwrap().to_owned())
|
||||
.collect();
|
||||
|
||||
packages.iter_mut().filter_map(move |(path, package)| {
|
||||
if members.contains(path) {
|
||||
if let MaybePackage::Package(ref mut p) = package {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns an iterator over default packages in this workspace
|
||||
pub fn default_members<'a>(&'a self) -> Members<'a, 'cfg> {
|
||||
Members {
|
||||
@ -481,6 +501,26 @@ impl<'cfg> Workspace<'cfg> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over default packages in this workspace
|
||||
pub fn default_members_mut(&mut self) -> impl Iterator<Item = &mut Package> {
|
||||
let packages = &mut self.packages.packages;
|
||||
let members: HashSet<_> = self
|
||||
.default_members
|
||||
.iter()
|
||||
.map(|path| path.parent().unwrap().to_owned())
|
||||
.collect();
|
||||
|
||||
packages.iter_mut().filter_map(move |(path, package)| {
|
||||
if members.contains(path) {
|
||||
if let MaybePackage::Package(ref mut p) = package {
|
||||
return Some(p);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns true if the package is a member of the workspace.
|
||||
pub fn is_member(&self, pkg: &Package) -> bool {
|
||||
self.member_ids.contains(&pkg.package_id())
|
||||
|
Loading…
x
Reference in New Issue
Block a user