Struct cargo_update::ops::MainRepoPackage [] [src]

pub struct MainRepoPackage {
    pub name: String,
    pub version: Option<Semver>,
    pub newest_version: Option<Semver>,
}

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 registry = get_index_path(&cargo_dir);
let package_s = "racer 1.2.10 (registry+https://github.com/rust-lang/crates.io-index)";
let mut package = MainRepoPackage::parse(package_s).unwrap();
assert_eq!(package,
           MainRepoPackage {
               name: "racer".to_string(),
               version: Some(Semver::parse("1.2.10").unwrap()),
               newest_version: None,
           });

package.pull_version(&registry);
assert!(package.newest_version.is_some());

Fields

The package's name.

Go to https://crates.io/crates/{name} to get the crate info.

The package's locally installed version.

The latest version of the package vailable at the main crates.io repository.

None by default, acquire via MainRepoPackage::pull_version().

Methods

impl MainRepoPackage
[src]

Try to decypher a package descriptor into a MainRepoPackage.

Will return None if:

  • the given package descriptor is invalid, or
  • the package descriptor is not from the main crates.io registry.

In the returned instance, newest_version is always None, get it via MainRepoPackage::pull_version().

Examples

Main repository packages:

let package_s = "racer 1.2.10 (registry+https://github.com/rust-lang/crates.io-index)";
assert_eq!(MainRepoPackage::parse(package_s).unwrap(),
           MainRepoPackage {
               name: "racer".to_string(),
               version: Some(Semver::parse("1.2.10").unwrap()),
               newest_version: None,
           });

let package_s = "cargo-outdated 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)";
assert_eq!(MainRepoPackage::parse(package_s).unwrap(),
           MainRepoPackage {
               name: "cargo-outdated".to_string(),
               version: Some(Semver::parse("0.2.0").unwrap()),
               newest_version: None,
           });

Git repository:

let package_s = "treesize 0.2.1 (git+https://github.com/melak47/treesize-rs#v0.2.1)";
assert!(MainRepoPackage::parse(package_s).is_none());

Download the version list for this crate off the main crates.io registry.

Examples

let registry = get_index_path(&cargo_dir);
let package_s = "racer 1.2.10 (registry+https://github.com/rust-lang/crates.io-index)";
let mut package = MainRepoPackage::parse(package_s).unwrap();
package.pull_version(&registry);
assert!(package.newest_version.is_some());

Check whether this package needs to be installed

Examples

assert!(MainRepoPackage {
            name: "racer".to_string(),
            version: Some(Semver::parse("1.7.2").unwrap()),
            newest_version: Some(Semver::parse("2.0.6").unwrap()),
        }.needs_update());
assert!(MainRepoPackage {
            name: "racer".to_string(),
            version: None,
            newest_version: Some(Semver::parse("2.0.6").unwrap()),
        }.needs_update());
assert!(!MainRepoPackage {
            name: "racer".to_string(),
            version: Some(Semver::parse("2.0.6").unwrap()),
            newest_version: Some(Semver::parse("2.0.6").unwrap()),
        }.needs_update());

Trait Implementations

impl Debug for MainRepoPackage
[src]

Formats the value using the given formatter.

impl Clone for MainRepoPackage
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Hash for MainRepoPackage
[src]

Feeds this value into the state given, updating the hasher as necessary.

Feeds a slice of this type into the state provided.

impl PartialEq for MainRepoPackage
[src]

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

This method tests for !=.

impl Eq for MainRepoPackage
[src]