Struct cargo::util::config::Config

source Ā·
pub struct Config {
    pub nightly_features_allowed: bool,
    pub ws_roots: RefCell<HashMap<PathBuf, WorkspaceRootConfig>>,
    /* private fields */
}
Expand description

Configuration information for cargo. This is not specific to a build, it is information relating to cargo itself.

FieldsĀ§

Ā§nightly_features_allowed: bool

This should be false if:

  • this is an artifact of the rustc distribution process for ā€œstableā€ or for ā€œbetaā€
  • this is an #[test] that does not opt in with enable_nightly_features
  • this is an integration test that uses ProcessBuilder that does not opt in with masquerade_as_nightly_cargo This should be true if:
  • this is an artifact of the rustc distribution process for ā€œnightlyā€
  • this is being used in the rustc distribution process internally
  • this is a cargo executable that was built from source
  • this is an #[test] that called enable_nightly_features
  • this is an integration test that uses ProcessBuilder that called masquerade_as_nightly_cargo Itā€™s public to allow tests use nightly features. NOTE: this should be set before configure(). If calling this from an integration test, consider using ConfigBuilder::enable_nightly_features instead.
Ā§ws_roots: RefCell<HashMap<PathBuf, WorkspaceRootConfig>>

WorkspaceRootConfigs that have been found

ImplementationsĀ§

sourceĀ§

impl Config

source

pub fn new(shell: Shell, cwd: PathBuf, homedir: PathBuf) -> Config

Creates a new config instance.

This is typically used for tests or other special cases. default is preferred otherwise.

This does only minimal initialization. In particular, it does not load any config files from disk. Those will be loaded lazily as-needed.

source

pub fn default() -> CargoResult<Config>

Creates a new Config instance, with all default settings.

This does only minimal initialization. In particular, it does not load any config files from disk. Those will be loaded lazily as-needed.

source

pub fn home(&self) -> &Filesystem

Gets the userā€™s Cargo home directory (OS-dependent).

source

pub fn diagnostic_home_config(&self) -> String

Returns a path to display to the user with the location of their home config file (to only be used for displaying a diagnostics suggestion, such as recommending where to add a config value).

source

pub fn git_path(&self) -> Filesystem

Gets the Cargo Git directory (<cargo_home>/git).

source

pub fn git_checkouts_path(&self) -> Filesystem

Gets the directory of code sources Cargo checkouts from Git bare repos (<cargo_home>/git/checkouts).

source

pub fn git_db_path(&self) -> Filesystem

Gets the directory for all Git bare repos Cargo clones (<cargo_home>/git/db).

source

pub fn registry_base_path(&self) -> Filesystem

Gets the Cargo base directory for all registry information (<cargo_home>/registry).

source

pub fn registry_index_path(&self) -> Filesystem

Gets the Cargo registry index directory (<cargo_home>/registry/index).

source

pub fn registry_cache_path(&self) -> Filesystem

Gets the Cargo registry cache directory (<cargo_home>/registry/cache).

source

pub fn registry_source_path(&self) -> Filesystem

Gets the Cargo registry source directory (<cargo_home>/registry/src).

source

pub fn default_registry(&self) -> CargoResult<Option<String>>

Gets the default Cargo registry.

source

pub fn shell(&self) -> RefMut<'_, Shell>

Gets a reference to the shell, e.g., for writing error messages.

source

pub fn rustdoc(&self) -> CargoResult<&Path>

Gets the path to the rustdoc executable.

source

pub fn load_global_rustc( &self, ws: Option<&Workspace<'_>> ) -> CargoResult<Rustc>

Gets the path to the rustc executable.

source

pub fn cargo_exe(&self) -> CargoResult<&Path>

Gets the path to the cargo executable.

source

pub fn updated_sources(&self) -> RefMut<'_, HashSet<SourceId>>

Which package sources have been updated, used to ensure it is only done once.

source

pub fn credential_cache( &self ) -> RefMut<'_, HashMap<CanonicalUrl, CredentialCacheValue>>

Cached credentials from credential providers or configuration.

source

pub fn values(&self) -> CargoResult<&HashMap<String, ConfigValue>>

Gets all config values from disk.

This will lazy-load the values as necessary. Callers are responsible for checking environment variables. Callers outside of the config module should avoid using this.

source

pub fn values_mut(&mut self) -> CargoResult<&mut HashMap<String, ConfigValue>>

Gets a mutable copy of the on-disk config values.

This requires the config values to already have been loaded. This currently only exists for cargo vendor to remove the source entries. This doesnā€™t respect environment variables. You should avoid using this if possible.

source

pub fn set_values( &self, values: HashMap<String, ConfigValue> ) -> CargoResult<()>

source

pub fn set_search_stop_path<P: Into<PathBuf>>(&mut self, path: P)

Sets the path where ancestor config file searching will stop. The given path is included, but its ancestors are not.

source

pub fn reload_rooted_at<P: AsRef<Path>>(&mut self, path: P) -> CargoResult<()>

Reloads on-disk configuration values, starting at the given path and walking up its ancestors.

source

pub fn cwd(&self) -> &Path

The current working directory.

source

pub fn target_dir(&self) -> CargoResult<Option<Filesystem>>

The target output directory to use.

Returns None if the user has not chosen an explicit directory.

Callers should prefer Workspace::target_dir instead.

source

pub fn set_env(&mut self, env: HashMap<String, String>)

Helper primarily for testing.

source

pub fn get_env(&self, key: impl AsRef<OsStr>) -> CargoResult<String>

Get the value of environment variable key through the Config snapshot.

This can be used similarly to std::env::var.

source

pub fn get_env_os(&self, key: impl AsRef<OsStr>) -> Option<OsString>

Get the value of environment variable key through the Config snapshot.

This can be used similarly to std::env::var_os.

source

pub fn get_string(&self, key: &str) -> CargoResult<OptValue<String>>

Get a string config value.

See get for more details.

source

pub fn get_path(&self, key: &str) -> CargoResult<OptValue<PathBuf>>

Get a config value that is expected to be a path.

This returns a relative path if the value does not contain any directory separators. See ConfigRelativePath::resolve_program for more details.

source

pub fn get_list( &self, key: &str ) -> CargoResult<OptValue<Vec<(String, Definition)>>>

Get a list of strings.

DO NOT USE outside of the config module. pub will be removed in the future.

NOTE: this does not support environment variables. Use get instead if you want that.

source

pub fn configure( &mut self, verbose: u32, quiet: bool, color: Option<&str>, frozen: bool, locked: bool, offline: bool, target_dir: &Option<PathBuf>, unstable_flags: &[String], cli_config: &[String] ) -> CargoResult<()>

Update the Config instance based on settings typically passed in on the command-line.

This may also load the config from disk if it hasnā€™t already been loaded.

source

pub fn cli_unstable(&self) -> &CliUnstable

source

pub fn extra_verbose(&self) -> bool

source

pub fn network_allowed(&self) -> bool

source

pub fn offline(&self) -> bool

source

pub fn frozen(&self) -> bool

source

pub fn locked(&self) -> bool

source

pub fn lock_update_allowed(&self) -> bool

source

pub fn load_values(&self) -> CargoResult<HashMap<String, ConfigValue>>

Loads configuration from the filesystem.

source

pub fn get_registry_index(&self, registry: &str) -> CargoResult<Url>

Gets the index for a registry.

source

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

Returns an error if registry.index is set.

source

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

Loads credentials config from the credentials file, if present.

The credentials are loaded into a separate field to enable them to be lazy-loaded after the main configuration has been loaded, without requiring mut access to the Config.

If the credentials are already loaded, this function does nothing.

source

pub fn jobserver_from_env(&self) -> Option<&Client>

source

pub fn http(&self) -> CargoResult<&RefCell<Easy>>

source

pub fn http_config(&self) -> CargoResult<&CargoHttpConfig>

source

pub fn future_incompat_config(&self) -> CargoResult<&CargoFutureIncompatConfig>

source

pub fn net_config(&self) -> CargoResult<&CargoNetConfig>

source

pub fn build_config(&self) -> CargoResult<&CargoBuildConfig>

source

pub fn progress_config(&self) -> &ProgressConfig

source

pub fn env_config(&self) -> CargoResult<&EnvConfig>

source

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

This is used to validate the term table has valid syntax.

This is necessary because loading the term settings happens very early, and in some situations (like cargo version) we donā€™t want to fail if there are problems with the config file.

source

pub fn target_cfgs(&self) -> CargoResult<&Vec<(String, TargetCfgConfig)>>

Returns a list of [target.ā€˜cfg()ā€™] tables.

The list is sorted by the table name.

source

pub fn doc_extern_map(&self) -> CargoResult<&RustdocExternMap>

source

pub fn target_applies_to_host(&self) -> CargoResult<bool>

Returns true if the [target] table should be applied to host targets.

source

pub fn host_cfg_triple(&self, target: &str) -> CargoResult<TargetConfig>

Returns the [host] table definition for the given target triple.

source

pub fn target_cfg_triple(&self, target: &str) -> CargoResult<TargetConfig>

Returns the [target] table definition for the given target triple.

source

pub fn crates_io_source_id(&self) -> CargoResult<SourceId>

Returns the cached SourceId corresponding to the main repository.

This is the main cargo registry by default, but it can be overridden in a .cargo/config.toml.

source

pub fn creation_time(&self) -> Instant

source

pub fn get<'de, T: Deserialize<'de>>(&self, key: &str) -> CargoResult<T>

Retrieves a config variable.

This supports most serde Deserialize types. Examples:

ā“˜
let v: Option<u32> = config.get("some.nested.key")?;
let v: Option<MyStruct> = config.get("some.key")?;
let v: Option<HashMap<String, MyStruct>> = config.get("foo")?;

The key may be a dotted key, but this does NOT support TOML key quoting. Avoid key components that may have dots. For example, foo.'a.b'.bar" does not work if you try to fetch foo.ā€˜a.bā€™ā€œ. You can fetch foo if it is a map, though.

source

pub fn assert_package_cache_locked<'a>( &self, mode: CacheLockMode, f: &'a Filesystem ) -> &'a Path

Obtain a Path from a Filesystem, verifying that the appropriate lock is already currently held.

Locks are usually acquired via Config::acquire_package_cache_lock or Config::try_acquire_package_cache_lock.

source

pub fn acquire_package_cache_lock( &self, mode: CacheLockMode ) -> CargoResult<CacheLock<'_>>

Acquires a lock on the global ā€œpackage cacheā€, blocking if another cargo holds the lock.

See crate::util::cache_lock for an in-depth discussion of locking and lock modes.

source

pub fn try_acquire_package_cache_lock( &self, mode: CacheLockMode ) -> CargoResult<Option<CacheLock<'_>>>

Acquires a lock on the global ā€œpackage cacheā€, returning None if another cargo holds the lock.

See crate::util::cache_lock for an in-depth discussion of locking and lock modes.

source

pub fn global_cache_tracker( &self ) -> CargoResult<RefMut<'_, GlobalCacheTracker>>

Returns a reference to the shared GlobalCacheTracker.

The package cache lock must be held to call this function (and to use it in general).

source

pub fn deferred_global_last_use( &self ) -> CargoResult<RefMut<'_, DeferredGlobalLastUse>>

Returns a reference to the shared DeferredGlobalLastUse.

Trait ImplementationsĀ§

sourceĀ§

impl Debug for Config

sourceĀ§

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

Formats the value using the given formatter. Read more

Auto Trait ImplementationsĀ§

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.

sourceĀ§

impl<T> Instrument for T

sourceĀ§

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

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

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.

sourceĀ§

impl<T> Pointable for T

sourceĀ§

const ALIGN: usize = _

The alignment of pointer.
Ā§

type Init = T

The type for initializers.
sourceĀ§

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

Initializes a with the given initializer. Read more
sourceĀ§

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

Dereferences the given pointer. Read more
sourceĀ§

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

Mutably dereferences the given pointer. Read more
sourceĀ§

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

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

sourceĀ§

fn vzip(self) -> V

sourceĀ§

impl<T> WithSubscriber for T

sourceĀ§

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
sourceĀ§

fn with_current_subscriber(self) -> WithDispatch<Self>

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