Skip to main content

Config

Struct Config 

Source
pub struct Config { /* private fields */ }
Expand description

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

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 git_path(&self) -> Filesystem

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

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/path).

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 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 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_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 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 get_default_registry_index(&self) -> CargoResult<Option<Url>>

Gets the index for the default registry.

Source

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

Loads credentials config from the credentials file, if present.

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 net_config(&self) -> CargoResult<&CargoNetConfig>

Source

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

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 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<F>(&self, f: F) -> CargoResult<SourceId>
where F: FnMut() -> CargoResult<SourceId>,

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, f: &'a Filesystem) -> &'a Path

Source

pub fn acquire_package_cache_lock(&self) -> CargoResult<PackageCacheLock<'_>>

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.

Source

pub fn release_package_cache_lock(&self)

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§

§

impl !Freeze for Config

§

impl !RefUnwindSafe for Config

§

impl !Send for Config

§

impl !Sync for Config

§

impl !UnwindSafe for Config

§

impl Unpin for Config

§

impl UnsafeUnpin for Config

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, 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.
Source§

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.