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(®istry_tree, ®istry);
assert!(package.newest_version.is_some());Fields§
§name: StringThe 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
impl RegistryPackage
Sourcepub fn parse(what: &str, executables: Vec<String>) -> Option<RegistryPackage>
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());Sourcepub fn pull_version(
&mut self,
registry: &RegistryTree<'_>,
registry_parent: &Registry,
install_prereleases: Option<bool>,
)
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.
Sourcepub fn needs_update(
&self,
req: Option<&SemverReq>,
install_prereleases: Option<bool>,
downdate: bool,
) -> bool
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));Sourcepub fn update_to_version(&self) -> Option<&Semver>
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
impl Clone for RegistryPackage
Source§fn clone(&self) -> RegistryPackage
fn clone(&self) -> RegistryPackage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RegistryPackage
impl Debug for RegistryPackage
Source§impl Hash for RegistryPackage
impl Hash for RegistryPackage
Source§impl PartialEq for RegistryPackage
impl PartialEq for RegistryPackage
impl Eq for RegistryPackage
impl StructuralPartialEq for RegistryPackage
Auto Trait Implementations§
impl Freeze for RegistryPackage
impl RefUnwindSafe for RegistryPackage
impl Send for RegistryPackage
impl Sync for RegistryPackage
impl Unpin for RegistryPackage
impl UnwindSafe for RegistryPackage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.