Struct cargo_update::ops::PackageConfig
source · pub struct PackageConfig {
pub toolchain: Option<String>,
pub default_features: bool,
pub features: BTreeSet<String>,
pub debug: 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.
target_version: Option<VersionReq>
Whether to compile in debug mode.
Implementations
sourceimpl PackageConfig
impl PackageConfig
sourcepub fn from<'o, O: IntoIterator<Item = &'o ConfigOperation>>(
ops: O
) -> PackageConfig
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::SetDebugMode(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),
target_version: Some(VersionReq::from_str(">=0.1").unwrap()),
});
sourcepub fn cargo_args(&self) -> Vec<String>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
pub fn cargo_args(&self) -> Vec<String>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A>where
A: Allocator,
A: Allocator,
Generate cargo arguments from this configuration.
Examples
let cmd = Command::new("cargo").args(configuration.get(&name).unwrap().cargo_args()).arg(&name)
// Process the command further -- run it, for example.
sourcepub fn execute_operations<'o, O: IntoIterator<Item = &'o ConfigOperation>>(
&mut self,
ops: O
)
pub fn execute_operations<'o, O: IntoIterator<Item = &'o ConfigOperation>>(
&mut self,
ops: O
)
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,
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),
target_version: None,
});
sourcepub fn read(p: &Path) -> Result<BTreeMap<String, PackageConfig>, i32>
pub fn read(p: &Path) -> Result<BTreeMap<String, PackageConfig>, i32>
Read a configset from the specified file.
If the specified file doesn’t exist an empty configset is returned.
Examples
File::create(&config_file).unwrap().write_all(&b"\
[cargo-update]\n\
default_features = true\n\
features = [\"serde\"]\n"[..]);
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,
target_version: None,
});
pkgs
}));
sourcepub fn write(
configuration: &BTreeMap<String, PackageConfig>,
p: &Path
) -> Result<(), i32>
pub fn write(
configuration: &BTreeMap<String, PackageConfig>,
p: &Path
) -> Result<(), i32>
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,
target_version: None,
});
pkgs
}, &config_file).unwrap();
let mut buf = String::new();
File::open(&config_file).unwrap().read_to_string(&mut buf).unwrap();
assert_eq!(&buf, "[cargo-update]\n\
default_features = true\n\
features = [\"serde\"]\n");
Trait Implementations
sourceimpl Clone for PackageConfig
impl Clone for PackageConfig
sourcefn clone(&self) -> PackageConfig
fn clone(&self) -> PackageConfig
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for PackageConfig
impl Debug for PackageConfig
sourceimpl Default for PackageConfig
impl Default for PackageConfig
sourcefn default() -> PackageConfig
fn default() -> PackageConfig
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for PackageConfig
impl<'de> Deserialize<'de> for PackageConfig
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Hash for PackageConfig
impl Hash for PackageConfig
sourceimpl Ord for PackageConfig
impl Ord for PackageConfig
sourcefn cmp(&self, other: &PackageConfig) -> Ordering
fn cmp(&self, other: &PackageConfig) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<PackageConfig> for PackageConfig
impl PartialEq<PackageConfig> for PackageConfig
sourcefn eq(&self, other: &PackageConfig) -> bool
fn eq(&self, other: &PackageConfig) -> bool
sourceimpl PartialOrd<PackageConfig> for PackageConfig
impl PartialOrd<PackageConfig> for PackageConfig
sourcefn partial_cmp(&self, other: &PackageConfig) -> Option<Ordering>
fn partial_cmp(&self, other: &PackageConfig) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresourceimpl Serialize for PackageConfig
impl Serialize for PackageConfig
impl Eq for PackageConfig
impl StructuralEq for PackageConfig
impl StructuralPartialEq for PackageConfig
Auto Trait Implementations
impl RefUnwindSafe for PackageConfig
impl Send for PackageConfig
impl Sync for PackageConfig
impl Unpin for PackageConfig
impl UnwindSafe for PackageConfig
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more