Struct cargo_update::ops::PackageConfig[][src]

pub struct PackageConfig {
    pub toolchain: Option<String>,
    pub default_features: bool,
    pub features: BTreeSet<String>,
    pub debug: Option<bool>,
    pub install_prereleases: Option<bool>,
    pub enforce_lock: Option<bool>,
    pub respect_binaries: Option<bool>,
    pub target_version: Option<VersionReq>,
}
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).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>

Whether to compile in debug mode.

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.

Implementations

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::SetDebugMode(true),
                                 ConfigOperation::SetInstallPrereleases(false),
                                 ConfigOperation::SetEnforceLock(true),
                                 ConfigOperation::SetRespectBinaries(true),
                                 ConfigOperation::SetTargetVersion(VersionReq::from_str(">=0.1").unwrap())]),
           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),
               install_prereleases: Some(false),
               enforce_lock: Some(true),
               respect_binaries: Some(true),
               target_version: Some(VersionReq::from_str(">=0.1").unwrap()),
           });

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.

Modify self according to the specified set of operations.

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,
    install_prereleases: None,
    enforce_lock: None,
    respect_binaries: None,
    target_version: Some(VersionReq::from_str(">=0.1").unwrap()),
};
cfg.execute_operations(&[ConfigOperation::RemoveToolchain,
                         ConfigOperation::AddFeature("serde".to_string()),
                         ConfigOperation::RemoveFeature("rustc-serialize".to_string()),
                         ConfigOperation::SetDebugMode(true),
                         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),
               install_prereleases: None,
               enforce_lock: None,
               respect_binaries: None,
               target_version: None,
           });

Read a configset from the specified file.

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), 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,
        install_prereleases: None,
        enforce_lock: None,
        respect_binaries: None,
        target_version: None,
    });
    pkgs
}));

Save a configset to the specified file.

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,
        install_prereleases: None,
        enforce_lock: None,
        respect_binaries: None,
        target_version: None,
    });
    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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. 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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.