PackageConfig

Struct PackageConfig 

Source
pub struct PackageConfig {
    pub toolchain: Option<String>,
    pub default_features: bool,
    pub features: BTreeSet<String>,
    pub debug: Option<bool>,
    pub build_profile: Option<Cow<'static, str>>,
    pub install_prereleases: Option<bool>,
    pub enforce_lock: Option<bool>,
    pub respect_binaries: Option<bool>,
    pub target_version: Option<VersionReq>,
    pub environment: Option<BTreeMap<String, EnvironmentOverride>>,
    pub from_transient: bool,
}
Expand description

Compilation configuration for one crate.

§Examples

Reading a configset, adding an entry to it, then writing it back.

let mut configuration = PackageConfig::read(&config_file, Path::new("/ENOENT")).unwrap();
configuration.insert("cargo_update".to_string(), PackageConfig::from(&operations));
PackageConfig::write(&configuration, &config_file).unwrap();

Fields§

§toolchain: Option<String>

Toolchain to use to compile the package, or None for default.

§default_features: bool

Whether to compile the package with the default features.

§features: BTreeSet<String>

Features to compile the package with.

§debug: Option<bool>

Equivalent to build_profile = Some("dev") but binds stronger

§build_profile: Option<Cow<'static, str>>

The build profile (test or bench or one from ~/.cargo/config.toml [profile.gaming]); CANNOT be dev (debug = Some(true)) or release (debug = build_profile = None)

§install_prereleases: Option<bool>

Whether to install pre-release versions.

§enforce_lock: Option<bool>

Whether to enforce Cargo.lock versions.

§respect_binaries: Option<bool>

Whether to install only the pre-configured binaries.

§target_version: Option<VersionReq>

Versions to constrain to.

§environment: Option<BTreeMap<String, EnvironmentOverride>>

Environment variables to alter for cargo. None to remove.

§from_transient: bool

Read in from .crates2.json, shouldn’t be saved

Implementations§

Source§

impl PackageConfig

Source

pub fn from<'o, O: IntoIterator<Item = &'o ConfigOperation>>( ops: O, ) -> PackageConfig

Create a package config based on the default settings and modified according to the specified operations.

§Examples
assert_eq!(PackageConfig::from(&[ConfigOperation::SetToolchain("nightly".to_string()),
                                 ConfigOperation::DefaultFeatures(false),
                                 ConfigOperation::AddFeature("rustc-serialize".to_string()),
                                 ConfigOperation::SetBuildProfile("dev".into()),
                                 ConfigOperation::SetInstallPrereleases(false),
                                 ConfigOperation::SetEnforceLock(true),
                                 ConfigOperation::SetRespectBinaries(true),
                                 ConfigOperation::SetTargetVersion(VersionReq::from_str(">=0.1").unwrap()),
                                 ConfigOperation::SetEnvironment("RUSTC_WRAPPER".to_string(), "sccache".to_string()),
                                 ConfigOperation::ClearEnvironment("CC".to_string())]),
           PackageConfig {
               toolchain: Some("nightly".to_string()),
               default_features: false,
               features: {
                   let mut feats = BTreeSet::new();
                   feats.insert("rustc-serialize".to_string());
                   feats
               },
               debug: Some(true),
               build_profile: None,
               install_prereleases: Some(false),
               enforce_lock: Some(true),
               respect_binaries: Some(true),
               target_version: Some(VersionReq::from_str(">=0.1").unwrap()),
               environment: Some({
                   let mut vars = BTreeMap::new();
                   vars.insert("RUSTC_WRAPPER".to_string(), EnvironmentOverride(Some("sccache".to_string())));
                   vars.insert("CC".to_string(), EnvironmentOverride(None));
                   vars
               }),
               from_transient: false,
           });
Source

pub fn cargo_args<S: AsRef<str>, I: IntoIterator<Item = S>>( &self, executables: I, ) -> Vec<Cow<'static, str>>

Generate cargo arguments from this configuration.

Executable names are stripped of their trailing ".exe", if any.

§Examples
let cmd = Command::new("cargo")
              .args(configuration.get(&name).unwrap().cargo_args(&["racer"]).iter().map(AsRef::as_ref))
              .arg(&name)
// Process the command further -- run it, for example.
Source

pub fn environmentalise<'c>(&self, cmd: &'c mut Command) -> &'c mut Command

Apply transformations from self.environment to cmd.

Source

pub fn execute_operations<'o, O: IntoIterator<Item = &'o ConfigOperation>>( &mut self, ops: O, )

Modify self according to the specified set of operations.

If this config was transient (read in from .crates2.json), it is made real and will be saved.

§Examples
let mut cfg = PackageConfig {
    toolchain: Some("nightly".to_string()),
    default_features: false,
    features: {
        let mut feats = BTreeSet::new();
        feats.insert("rustc-serialize".to_string());
        feats
    },
    debug: None,
    build_profile: None,
    install_prereleases: None,
    enforce_lock: None,
    respect_binaries: None,
    target_version: Some(VersionReq::from_str(">=0.1").unwrap()),
    environment: None,
    from_transient: false,
};
cfg.execute_operations(&[ConfigOperation::RemoveToolchain,
                         ConfigOperation::AddFeature("serde".to_string()),
                         ConfigOperation::RemoveFeature("rustc-serialize".to_string()),
                         ConfigOperation::SetBuildProfile("dev".into()),
                         ConfigOperation::RemoveTargetVersion]);
assert_eq!(cfg,
           PackageConfig {
               toolchain: None,
               default_features: false,
               features: {
                   let mut feats = BTreeSet::new();
                   feats.insert("serde".to_string());
                   feats
               },
               debug: Some(true),
               build_profile: None,
               install_prereleases: None,
               enforce_lock: None,
               respect_binaries: None,
               target_version: None,
               environment: None,
               from_transient: false,
           });
Source

pub fn read( p: &Path, cargo2_json: &Path, ) -> Result<BTreeMap<String, PackageConfig>, (String, i32)>

Read a configset from the specified file, or from the given .cargo2.json.

The first file (usually .install_config.toml) is used by default for each package; .cargo2.json, if any, is used to backfill existing data from cargo.

If the specified file doesn’t exist an empty configset is returned.

§Examples
fs::write(&config_file, &b"\
   [cargo-update]\n\
   default_features = true\n\
   features = [\"serde\"]\n"[..]).unwrap();
assert_eq!(PackageConfig::read(&config_file, Path::new("/ENOENT")), Ok({
    let mut pkgs = BTreeMap::new();
    pkgs.insert("cargo-update".to_string(), PackageConfig {
        toolchain: None,
        default_features: true,
        features: {
            let mut feats = BTreeSet::new();
            feats.insert("serde".to_string());
            feats
        },
        debug: None,
        build_profile: None,
        install_prereleases: None,
        enforce_lock: None,
        respect_binaries: None,
        target_version: None,
        environment: None,
        from_transient: false,
    });
    pkgs
}));
Source

pub fn write( configuration: &BTreeMap<String, PackageConfig>, p: &Path, ) -> Result<(), (String, i32)>

Save a configset to the specified file, transient (.crates2.json) configs are removed.

§Examples
PackageConfig::write(&{
    let mut pkgs = BTreeMap::new();
    pkgs.insert("cargo-update".to_string(), PackageConfig {
        toolchain: None,
        default_features: true,
        features: {
            let mut feats = BTreeSet::new();
            feats.insert("serde".to_string());
            feats
        },
        debug: None,
        build_profile: None,
        install_prereleases: None,
        enforce_lock: None,
        respect_binaries: None,
        target_version: None,
        environment: None,
        from_transient: false,
    });
    pkgs
}, &config_file).unwrap();

assert_eq!(&fs::read_to_string(&config_file).unwrap(),
           "[cargo-update]\n\
            default_features = true\n\
            features = [\"serde\"]\n");

Trait Implementations§

Source§

impl Clone for PackageConfig

Source§

fn clone(&self) -> PackageConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PackageConfig

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PackageConfig

Source§

fn default() -> PackageConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PackageConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for PackageConfig

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PackageConfig

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for PackageConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for PackageConfig

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,