Skip to main content

RegistryPackage

Struct RegistryPackage 

Source
pub struct RegistryPackage {
    pub name: String,
    pub registry: Cow<'static, str>,
    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".into(),
               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: Cow<'static, str>

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".into(),
               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".into(),
               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>, released_after: Option<DateTime<Utc>>, )

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".into(),
            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".into(),
            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".into(),
            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".into(),
            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".into(),
            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".into(),
            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".into(),
            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".into(),
            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".into(),
            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".into(),
            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".into(),
               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".into(),
               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 duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Eq for RegistryPackage

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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

Checks if this value is equivalent to the given key. 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> ErasedDestructor for T
where T: 'static,

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,

Source§

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

Source§

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

Source§

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.