Struct cargo::core::workspace::Workspace

source ·
pub struct Workspace<'gctx> {
Show 15 fields gctx: &'gctx GlobalContext, current_manifest: PathBuf, packages: Packages<'gctx>, 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, honor_rust_version: Option<bool>, 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§

§gctx: &'gctx GlobalContext§current_manifest: PathBuf§packages: Packages<'gctx>§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.

§honor_rust_version: Option<bool>§custom_metadata: Option<Value>

Workspace-level custom metadata

Implementations§

source§

impl<'gctx> Workspace<'gctx>

source

pub fn new( manifest_path: &Path, gctx: &'gctx GlobalContext ) -> CargoResult<Workspace<'gctx>>

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.

source

fn new_default( current_manifest: PathBuf, gctx: &'gctx GlobalContext ) -> Workspace<'gctx>

source

pub fn new_virtual( root_path: PathBuf, current_manifest: PathBuf, manifest: VirtualManifest, gctx: &'gctx GlobalContext ) -> CargoResult<Workspace<'gctx>>

source

pub fn ephemeral( package: Package, gctx: &'gctx GlobalContext, target_dir: Option<Filesystem>, require_optional_deps: bool ) -> CargoResult<Workspace<'gctx>>

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.

source

fn set_resolve_behavior(&mut self)

source

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.

source

pub fn current_mut(&mut self) -> CargoResult<&mut Package>

source

pub fn current_opt(&self) -> Option<&Package>

source

pub fn current_opt_mut(&mut self) -> Option<&mut Package>

source

pub fn is_virtual(&self) -> bool

source

pub fn gctx(&self) -> &'gctx GlobalContext

Returns the GlobalContext this workspace is associated with.

source

pub fn profiles(&self) -> Option<&TomlProfiles>

source

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.

source

pub fn root_manifest(&self) -> &Path

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

source

pub fn root_maybe(&self) -> &MaybePackage

Returns the root Package or VirtualManifest.

source

pub fn target_dir(&self) -> Filesystem

source

fn default_target_dir(&self) -> Filesystem

source

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.

source

fn config_patch(&self) -> CargoResult<HashMap<Url, Vec<Dependency>>>

source

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.

source

pub fn members(&self) -> impl Iterator<Item = &Package>

Returns an iterator over all packages in this workspace

source

pub fn members_mut(&mut self) -> impl Iterator<Item = &mut Package>

Returns a mutable iterator over all packages in this workspace

source

pub fn default_members<'a>(&'a self) -> impl Iterator<Item = &Package>

Returns an iterator over default packages in this workspace

source

pub fn default_members_mut(&mut self) -> impl Iterator<Item = &mut Package>

Returns an iterator over default packages in this workspace

source

pub fn is_member(&self, pkg: &Package) -> bool

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

source

pub fn is_ephemeral(&self) -> bool

source

pub fn require_optional_deps(&self) -> bool

source

pub fn set_require_optional_deps( &mut self, require_optional_deps: bool ) -> &mut Workspace<'gctx>

source

pub fn ignore_lock(&self) -> bool

source

pub fn set_ignore_lock(&mut self, ignore_lock: bool) -> &mut Workspace<'gctx>

source

pub fn rust_version(&self) -> Option<&RustVersion>

Get the lowest-common denominator package.rust-version within the workspace, if specified anywhere

source

pub fn set_honor_rust_version(&mut self, honor_rust_version: Option<bool>)

source

pub fn honor_rust_version(&self) -> Option<bool>

source

pub fn resolve_honors_rust_version(&self) -> bool

source

pub fn custom_metadata(&self) -> Option<&Value>

source

pub fn load_workspace_config( &mut self ) -> CargoResult<Option<WorkspaceRootConfig>>

source

fn find_root(&mut self, manifest_path: &Path) -> CargoResult<Option<PathBuf>>

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.

source

fn find_members(&mut self) -> CargoResult<()>

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.

source

fn find_path_deps( &mut self, manifest_path: &Path, root_manifest: &Path, is_path_dep: bool ) -> CargoResult<()>

source

pub fn unstable_features(&self) -> &Features

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

source

pub fn resolve_behavior(&self) -> ResolveBehavior

source

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.

source

fn validate(&mut self) -> CargoResult<()>

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.
source

fn validate_unique_names(&self) -> CargoResult<()>

source

fn validate_workspace_roots(&self) -> CargoResult<()>

source

fn validate_members(&mut self) -> CargoResult<()>

source

fn error_if_manifest_not_in_members(&mut self) -> CargoResult<()>

source

fn validate_manifest(&mut self) -> CargoResult<()>

source

pub fn load(&self, manifest_path: &Path) -> CargoResult<Package>

source

pub fn preload(&self, registry: &mut PackageRegistry<'gctx>)

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.

source

pub fn emit_warnings(&self) -> CargoResult<()>

source

pub fn emit_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()>

source

pub fn set_target_dir(&mut self, target_dir: Filesystem)

source

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.

source

fn collect_matching_features( member: &Package, cli_features: &CliFeatures, found_features: &mut BTreeSet<FeatureValue> ) -> CliFeatures

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

source

fn report_unknown_features_error( &self, specs: &[PackageIdSpec], cli_features: &CliFeatures, found_features: &BTreeSet<FeatureValue> ) -> CargoResult<()>

source

fn members_with_features_new( &self, specs: &[PackageIdSpec], cli_features: &CliFeatures ) -> CargoResult<Vec<(&Package, CliFeatures)>>

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

source

fn members_with_features_old( &self, specs: &[PackageIdSpec], cli_features: &CliFeatures ) -> Vec<(&Package, CliFeatures)>

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

source

pub fn unit_needs_doc_scrape(&self, unit: &Unit) -> bool

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

Trait Implementations§

source§

impl<'gctx> Debug for Workspace<'gctx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'gctx> !Freeze for Workspace<'gctx>

§

impl<'gctx> !RefUnwindSafe for Workspace<'gctx>

§

impl<'gctx> !Send for Workspace<'gctx>

§

impl<'gctx> !Sync for Workspace<'gctx>

§

impl<'gctx> Unpin for Workspace<'gctx>

§

impl<'gctx> !UnwindSafe for Workspace<'gctx>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

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: 328 bytes