Struct cargo_update::ops::RegistryPackage [−][src]
pub struct RegistryPackage {
pub name: String,
pub registry: String,
pub version: Option<Semver>,
pub newest_version: Option<Semver>,
pub alternative_version: Option<Semver>,
pub max_version: Option<Semver>,
pub executables: Vec<String>,
}
Expand description
A representation of a package from the main crates.io
repository.
The newest version of a package is pulled from crates.io
via pull_version()
.
The parse()
function parses the format used in $HOME/.cargo/.crates.toml
.
Examples
let package_s = "racer 1.2.10 (registry+https://github.com/rust-lang/crates.io-index)";
let mut package = RegistryPackage::parse(package_s, vec!["racer.exe".to_string()]).unwrap();
assert_eq!(package,
RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("1.2.10").unwrap()),
newest_version: None,
alternative_version: None,
max_version: None,
executables: vec!["racer.exe".to_string()],
});
package.pull_version(®istry_tree, ®istry);
assert!(package.newest_version.is_some());
Fields
name: String
The package’s name.
Go to https://crates.io/crates/{name}
to get the crate info, if available on the main repository.
registry: String
The registry the package is available from.
Can be a name from ~/.cargo/config.
The main repository is https://github.com/rust-lang/crates.io-index
version: Option<Semver>
The package’s locally installed version.
newest_version: Option<Semver>
The latest version of the package, available at crates.io
, if in main repository.
None
by default, acquire via RegistryPackage::pull_version()
.
alternative_version: Option<Semver>
If present, the alternative newest version not chosen because of unfulfilled requirements like (not) being a prerelease.
max_version: Option<Semver>
User-bounded maximum version to update up to.
executables: Vec<String>
Executables currently installed for this package.
Implementations
Try to decypher a package descriptor into a RegistryPackage
.
Will return None
if the given package descriptor is invalid.
In the returned instance, newest_version
is always None
, get it via RegistryPackage::pull_version()
.
The executable list is used as-is.
Examples
Main repository packages:
let package_s = "racer 1.2.10 (registry+https://github.com/rust-lang/crates.io-index)";
assert_eq!(RegistryPackage::parse(package_s, vec!["racer.exe".to_string()]).unwrap(),
RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("1.2.10").unwrap()),
newest_version: None,
alternative_version: None,
max_version: None,
executables: vec!["racer.exe".to_string()],
});
let package_s = "cargo-outdated 0.2.0 (registry+file:///usr/local/share/cargo)";
assert_eq!(RegistryPackage::parse(package_s, vec!["cargo-outdated".to_string()]).unwrap(),
RegistryPackage {
name: "cargo-outdated".to_string(),
registry: "file:///usr/local/share/cargo".to_string(),
version: Some(Semver::parse("0.2.0").unwrap()),
newest_version: None,
alternative_version: None,
max_version: None,
executables: vec!["cargo-outdated".to_string()],
});
Git repository:
let package_s = "treesize 0.2.1 (git+https://github.com/melak47/treesize-rs#v0.2.1)";
assert!(RegistryPackage::parse(package_s, vec!["treesize".to_string()]).is_none());
pub fn pull_version<'t>(
&mut self,
registry: &Tree<'t>,
registry_parent: &'t Repository,
install_prereleases: Option<bool>
)
pub fn pull_version<'t>(
&mut self,
registry: &Tree<'t>,
registry_parent: &'t Repository,
install_prereleases: Option<bool>
)
Download the version list for this crate off the specified repository tree and set the latest and alternative versions.
Check whether this package needs to be installed
Examples
assert!(RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("1.7.2").unwrap()),
newest_version: Some(Semver::parse("2.0.6").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(None, None, false));
assert!(RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: None,
newest_version: Some(Semver::parse("2.0.6").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(None, None, false));
assert!(RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("2.0.7").unwrap()),
newest_version: Some(Semver::parse("2.0.6").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(None, None, true));
assert!(!RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("2.0.6").unwrap()),
newest_version: Some(Semver::parse("2.0.6").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(None, None, false));
assert!(!RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("2.0.6").unwrap()),
newest_version: None,
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(None, None, false));
let req = SemverReq::from_str("^1.7").unwrap();
assert!(RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("1.7.2").unwrap()),
newest_version: Some(Semver::parse("1.7.3").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(Some(&req), None, false));
assert!(RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: None,
newest_version: Some(Semver::parse("2.0.6").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(Some(&req), None, false));
assert!(!RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("1.7.2").unwrap()),
newest_version: Some(Semver::parse("2.0.6").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(Some(&req), None, false));
assert!(!RegistryPackage {
name: "cargo-audit".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: None,
newest_version: Some(Semver::parse("0.9.0-beta2").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(Some(&req), None, false));
assert!(RegistryPackage {
name: "cargo-audit".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: None,
newest_version: Some(Semver::parse("0.9.0-beta2").unwrap()),
alternative_version: None,
max_version: None,
executables: vec!["racer".to_string()],
}.needs_update(Some(&req), Some(true), false));
Get package version to update to, or None
if the crate has no newest version (was yanked)
Examples
assert_eq!(RegistryPackage {
name: "racer".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("1.7.2").unwrap()),
newest_version: Some(Semver::parse("2.0.6").unwrap()),
alternative_version: None,
max_version: Some(Semver::parse("2.0.5").unwrap()),
executables: vec!["racer".to_string()],
}.update_to_version(),
Some(&Semver::parse("2.0.5").unwrap()));
assert_eq!(RegistryPackage {
name: "gutenberg".to_string(),
registry: "https://github.com/rust-lang/crates.io-index".to_string(),
version: Some(Semver::parse("0.0.7").unwrap()),
newest_version: None,
alternative_version: None,
max_version: None,
executables: vec!["gutenberg".to_string()],
}.update_to_version(),
None);
Trait Implementations
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for RegistryPackage
impl Send for RegistryPackage
impl Sync for RegistryPackage
impl Unpin for RegistryPackage
impl UnwindSafe for RegistryPackage
Blanket Implementations
Mutably borrows from an owned value. Read more