Struct cargo::core::Workspace

source ·
pub struct Workspace<'cfg> {
Show 14 fields config: &'cfg Config, current_manifest: PathBuf, packages: Packages<'cfg>, root_manifest: Option<PathBuf>, target_dir: Option<Filesystem>, members: Vec<PathBuf>, member_ids: HashSet<PackageId>, default_members: Vec<PathBuf>, is_ephemeral: bool, require_optional_deps: bool, loaded_packages: RefCell<HashMap<PathBuf, Package>>, ignore_lock: bool, resolve_behavior: ResolveBehavior, custom_metadata: Option<Value>,
}
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.

Fields§

§config: &'cfg Config§current_manifest: PathBuf§packages: Packages<'cfg>§root_manifest: Option<PathBuf>§target_dir: Option<Filesystem>§members: Vec<PathBuf>§member_ids: HashSet<PackageId>§default_members: Vec<PathBuf>§is_ephemeral: bool§require_optional_deps: bool§loaded_packages: RefCell<HashMap<PathBuf, Package>>§ignore_lock: bool§resolve_behavior: ResolveBehavior

The resolver behavior specified with the resolver field.

§custom_metadata: Option<Value>

Workspace-level custom metadata

Implementations§

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.

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.

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.

Returns the Config this workspace is associated with.

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.

Returns the path of the Cargo.toml which is the root of this workspace.

Returns the root Package or VirtualManifest.

Returns the root [replace] section of this workspace.

This may be from a virtual crate or an actual crate.

Returns the root [patch] section of this workspace.

This may be from a virtual crate or an actual crate.

Returns an iterator over all packages in this workspace

Returns a mutable iterator over all packages in this workspace

Returns an iterator over default packages in this workspace

Returns an iterator over default packages in this workspace

Returns true if the package is a member of the workspace.

Finds the root of a workspace for the crate whose manifest is located at manifest_path.

This will parse the Cargo.toml at manifest_path and then interpret the workspace configuration, optionally walking up the filesystem looking for other workspace roots.

Returns an error if manifest_path isn’t actually a valid manifest or if some other transient error happens.

After the root of a workspace has been located, probes for all members of a workspace.

If the workspace.members configuration is present, then this just verifies that those are all valid packages to point to. Otherwise, this will transitively follow all path dependencies looking for members of the workspace.

Returns the unstable nightly-only features enabled via cargo-features in the manifest.

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.

Validates a workspace, ensuring that a number of invariants are upheld:

  1. A workspace only has one root.
  2. All workspace members agree on this one root as the root.
  3. The current crate is a member of this workspace.

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.

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.

Returns the requested features for the given member. This filters out any named features that the member does not have.

New command-line feature selection behavior with resolver = “2” or the root of a virtual workspace. See allows_new_cli_feature_behavior.

This is the “old” behavior for command-line feature selection. See allows_new_cli_feature_behavior.

Returns true if unit should depend on the output of Docscrape units.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.

Size: 376 bytes