pub struct RegistryPackage {
    pub name: String,
    pub registry: String,
    pub version: Option<Version>,
    pub newest_version: Option<Version>,
    pub alternative_version: Option<Version>,
    pub max_version: Option<Version>,
    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(&registry_tree, &registry);
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, or sparse+https://index.crates.io/.

§version: Option<Version>

The package’s locally installed version.

§newest_version: Option<Version>

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<Version>

If present, the alternative newest version not chosen because of unfulfilled requirements like (not) being a prerelease.

§max_version: Option<Version>

User-bounded maximum version to update up to.

§executables: Vec<String>

Executables currently installed for this package.

Implementations§

source§

impl RegistryPackage

source

pub fn parse(what: &str, executables: Vec<String>) -> Option<RegistryPackage>

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());
source

pub fn pull_version( &mut self, registry: &RegistryTree<'_>, registry_parent: &Registry, install_prereleases: Option<bool> )

Read the version list for this crate off the specified repository tree and set the latest and alternative versions.

source

pub fn needs_update( &self, req: Option<&SemverReq>, install_prereleases: Option<bool>, downdate: bool ) -> bool

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));
source

pub fn update_to_version(&self) -> Option<&Semver>

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§

source§

impl Clone for RegistryPackage

source§

fn clone(&self) -> RegistryPackage

Returns a copy 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 RegistryPackage

source§

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

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

impl Hash for RegistryPackage

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 RegistryPackage

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for RegistryPackage

source§

impl StructuralPartialEq for RegistryPackage

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<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,

§

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>,

§

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>,

§

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.