pub struct Config {
    pub nightly_features_allowed: bool,
    /* 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 a 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 a 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.

Implementations

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.

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.

Gets the user’s Cargo home directory (OS-dependent).

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

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

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

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

Gets the default Cargo registry.

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

Gets the path to the rustdoc executable.

Gets the path to the rustc executable.

Gets the path to the cargo executable.

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

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.

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.

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

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

The current working directory.

The target output directory to use.

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

Callers should prefer Workspace::target_dir instead.

Helper primarily for testing.

Get a string config value.

See get for more details.

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.

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.

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.

Loads configuration from the filesystem.

Gets the index for a registry.

Returns an error if registry.index is set.

Loads credentials config from the credentials file, if present.

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.

Returns a list of [target.‘cfg()’] tables.

The list is sorted by the table name.

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

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.

Acquires an exclusive lock on the global “package cache”

This lock is global per-process and can be acquired recursively. An RAII structure is returned to release the lock, and if this process abnormally terminates the lock is also released.

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.