Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,33 @@ impl<'cfg> Workspace<'cfg> {
Ok(pkg)
}

pub fn current_mut(&mut self) -> CargoResult<&mut Package> {
let cm = self.current_manifest.clone();
let pkg = self.current_opt_mut().ok_or_else(|| {
anyhow::format_err!(
"manifest path `{}` is a virtual manifest, but this \
command requires running against an actual package in \
this workspace",
cm.display()
)
})?;
Ok(pkg)
}

pub fn current_opt(&self) -> Option<&Package> {
match *self.packages.get(&self.current_manifest) {
MaybePackage::Package(ref p) => Some(p),
MaybePackage::Virtual(..) => None,
}
}

pub fn current_opt_mut(&mut self) -> Option<&mut Package> {
match *self.packages.get_mut(&self.current_manifest) {
MaybePackage::Package(ref mut p) => Some(p),
MaybePackage::Virtual(..) => None,
}
}

pub fn is_virtual(&self) -> bool {
match *self.packages.get(&self.current_manifest) {
MaybePackage::Package(..) => false,
Expand Down Expand Up @@ -825,10 +845,18 @@ impl<'cfg> Packages<'cfg> {
self.maybe_get(manifest_path).unwrap()
}

fn get_mut(&mut self, manifest_path: &Path) -> &mut MaybePackage {
self.maybe_get_mut(manifest_path).unwrap()
}

fn maybe_get(&self, manifest_path: &Path) -> Option<&MaybePackage> {
self.packages.get(manifest_path.parent().unwrap())
}

fn maybe_get_mut(&mut self, manifest_path: &Path) -> Option<&mut MaybePackage> {
self.packages.get_mut(manifest_path.parent().unwrap())
}

fn load(&mut self, manifest_path: &Path) -> CargoResult<&MaybePackage> {
let key = manifest_path.parent().unwrap();
match self.packages.entry(key.to_path_buf()) {
Expand Down