pub struct Workspace<'cfg> { /* private fields */ }
Expand description
The core abstraction in Cargo for working with a workspace of crates.
A workspace is often created very early on and then threaded through all other functions. It’s typically through this object that the current package is loaded and/or learned about.
Implementations
sourceimpl<'cfg> Workspace<'cfg>
impl<'cfg> Workspace<'cfg>
sourcepub fn new(
manifest_path: &Path,
config: &'cfg Config
) -> CargoResult<Workspace<'cfg>>
pub fn new(
manifest_path: &Path,
config: &'cfg Config
) -> CargoResult<Workspace<'cfg>>
Creates a new workspace given the target manifest pointed to by
manifest_path
.
This function will construct the entire workspace by determining the
root and all member packages. It will then validate the workspace
before returning it, so Ok
is only returned for valid workspaces.
pub fn new_virtual(
root_path: PathBuf,
current_manifest: PathBuf,
manifest: VirtualManifest,
config: &'cfg Config
) -> CargoResult<Workspace<'cfg>>
sourcepub fn ephemeral(
package: Package,
config: &'cfg Config,
target_dir: Option<Filesystem>,
require_optional_deps: bool
) -> CargoResult<Workspace<'cfg>>
pub fn ephemeral(
package: Package,
config: &'cfg Config,
target_dir: Option<Filesystem>,
require_optional_deps: bool
) -> CargoResult<Workspace<'cfg>>
Creates a “temporary workspace” from one package which only contains that package.
This constructor will not touch the filesystem and only creates an in-memory workspace. That is, all configuration is ignored, it’s just intended for that one package.
This is currently only used in niche situations like cargo install
or
cargo package
.
sourcepub fn current(&self) -> CargoResult<&Package>
pub fn current(&self) -> CargoResult<&Package>
Returns the current package of this workspace.
Note that this can return an error if it the current manifest is actually a “virtual Cargo.toml”, in which case an error is returned indicating that something else should be passed.
pub fn current_mut(&mut self) -> CargoResult<&mut Package>
pub fn current_opt(&self) -> Option<&Package>
pub fn current_opt_mut(&mut self) -> Option<&mut Package>
pub fn is_virtual(&self) -> bool
pub fn profiles(&self) -> Option<&TomlProfiles>
sourcepub fn root(&self) -> &Path
pub fn root(&self) -> &Path
Returns the root path of this workspace.
That is, this returns the path of the directory containing the
Cargo.toml
which is the root of this workspace.
sourcepub fn root_manifest(&self) -> &Path
pub fn root_manifest(&self) -> &Path
Returns the path of the Cargo.toml
which is the root of this
workspace.
sourcepub fn root_maybe(&self) -> &MaybePackage
pub fn root_maybe(&self) -> &MaybePackage
Returns the root Package or VirtualManifest.
pub fn target_dir(&self) -> Filesystem
sourcepub fn root_replace(&self) -> &[(PackageIdSpec, Dependency)]
pub fn root_replace(&self) -> &[(PackageIdSpec, Dependency)]
Returns the root [replace]
section of this workspace.
This may be from a virtual crate or an actual crate.
sourcepub fn root_patch(&self) -> CargoResult<HashMap<Url, Vec<Dependency>>>
pub fn root_patch(&self) -> CargoResult<HashMap<Url, Vec<Dependency>>>
Returns the root [patch]
section of this workspace.
This may be from a virtual crate or an actual crate.
sourcepub fn members<'a>(&'a self) -> Members<'a, 'cfg>ⓘNotable traits for Members<'a, 'cfg>impl<'a, 'cfg> Iterator for Members<'a, 'cfg> type Item = &'a Package;
pub fn members<'a>(&'a self) -> Members<'a, 'cfg>ⓘNotable traits for Members<'a, 'cfg>impl<'a, 'cfg> Iterator for Members<'a, 'cfg> type Item = &'a Package;
Returns an iterator over all packages in this workspace
sourcepub fn default_members<'a>(&'a self) -> Members<'a, 'cfg>ⓘNotable traits for Members<'a, 'cfg>impl<'a, 'cfg> Iterator for Members<'a, 'cfg> type Item = &'a Package;
pub fn default_members<'a>(&'a self) -> Members<'a, 'cfg>ⓘNotable traits for Members<'a, 'cfg>impl<'a, 'cfg> Iterator for Members<'a, 'cfg> type Item = &'a Package;
Returns an iterator over default packages in this workspace
sourcepub fn is_member(&self, pkg: &Package) -> bool
pub fn is_member(&self, pkg: &Package) -> bool
Returns true if the package is a member of the workspace.
pub fn is_ephemeral(&self) -> bool
pub fn require_optional_deps(&self) -> bool
pub fn set_require_optional_deps(
&mut self,
require_optional_deps: bool
) -> &mut Workspace<'cfg>
pub fn ignore_lock(&self) -> bool
pub fn set_ignore_lock(&mut self, ignore_lock: bool) -> &mut Workspace<'cfg>
pub fn custom_metadata(&self) -> Option<&Value>
pub fn load_workspace_config(
&mut self
) -> CargoResult<Option<WorkspaceRootConfig>>
sourcepub fn unstable_features(&self) -> &Features
pub fn unstable_features(&self) -> &Features
Returns the unstable nightly-only features enabled via cargo-features
in the manifest.
pub fn resolve_behavior(&self) -> ResolveBehavior
sourcepub fn allows_new_cli_feature_behavior(&self) -> bool
pub fn allows_new_cli_feature_behavior(&self) -> bool
Returns true
if this workspace uses the new CLI features behavior.
The old behavior only allowed choosing the features from the package in the current directory, regardless of which packages were chosen with the -p flags. The new behavior allows selecting features from the packages chosen on the command line (with -p or –workspace flags), ignoring whatever is in the current directory.
pub fn load(&self, manifest_path: &Path) -> CargoResult<Package>
sourcepub fn preload(&self, registry: &mut PackageRegistry<'cfg>)
pub fn preload(&self, registry: &mut PackageRegistry<'cfg>)
Preload the provided registry with already loaded packages.
A workspace may load packages during construction/parsing/early phases for various operations, and this preload step avoids doubly-loading and parsing crates on the filesystem by inserting them all into the registry with their in-memory formats.
pub fn emit_warnings(&self) -> CargoResult<()>
pub fn set_target_dir(&mut self, target_dir: Filesystem)
sourcepub fn members_with_features(
&self,
specs: &[PackageIdSpec],
cli_features: &CliFeatures
) -> CargoResult<Vec<(&Package, CliFeatures)>>
pub fn members_with_features(
&self,
specs: &[PackageIdSpec],
cli_features: &CliFeatures
) -> CargoResult<Vec<(&Package, CliFeatures)>>
Returns a Vec of (&Package, RequestedFeatures)
tuples that
represent the workspace members that were requested on the command-line.
specs
may be empty, which indicates it should return all workspace
members. In this case, requested_features.all_features
must be
true
. This is used for generating Cargo.lock
, which must include
all members with all features enabled.
Trait Implementations
Auto Trait Implementations
impl<'cfg> !RefUnwindSafe for Workspace<'cfg>
impl<'cfg> !Send for Workspace<'cfg>
impl<'cfg> !Sync for Workspace<'cfg>
impl<'cfg> Unpin for Workspace<'cfg>
impl<'cfg> !UnwindSafe for Workspace<'cfg>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more