SourceVersionSpecifier

Struct SourceVersionSpecifier 

Source
pub struct SourceVersionSpecifier { /* private fields */ }
Expand description

Source/version specifier. It is a constraint defined by a specific crate::Dependency, and is used by package managers to choose a specific crate::PackageSource.

§Example

let svs1 = SourceVersionSpecifier::new(
    "^1.0.0".to_string()).unwrap();
assert!(svs1.is_npm());

let svs2 = SourceVersionSpecifier::new(
    "git@codeberg.org:22/selfisekai/chaste.git".to_string()).unwrap();
assert!(svs2.is_git());

let svs3 = SourceVersionSpecifier::new(
    "https://s.lnl.gay/YMSRcUPRNMxx.tgz".to_string()).unwrap();
assert!(svs3.is_tar());

Implementations§

Source§

impl SourceVersionSpecifier

Source

pub fn new(svs: String) -> Result<Self>

Source

pub fn with_quirks(svs: String, quirks: QuirksMode) -> Result<Self>

Source§

impl SourceVersionSpecifier

Source

pub fn is_npm(&self) -> bool

Whether the SVS chooses an npm version range. This does not include npm tags (see SourceVersionSpecifier::is_npm_tag).

§Example
let svs1 = SourceVersionSpecifier::new(
    "^4".to_string()).unwrap();
assert!(svs1.is_npm());

let svs2 = SourceVersionSpecifier::new(
    "npm:@chastelock/testcase@^2.1.37".to_string()).unwrap();
assert!(svs2.is_npm());
Source

pub fn is_npm_tag(&self) -> bool

Whether the SVS chooses an npm tag. This does not include npm version ranges (see SourceVersionSpecifier::is_npm).

§Example
let svs1 = SourceVersionSpecifier::new(
    "latest".to_string()).unwrap();
assert!(svs1.is_npm_tag());

let svs2 = SourceVersionSpecifier::new(
    "next-11".to_string()).unwrap();
assert!(svs2.is_npm_tag());
Source

pub fn is_tar(&self) -> bool

Whether the SVS chooses an arbitrary tarball URL.

§Example
let svs1 = SourceVersionSpecifier::new(
    "https://s.lnl.gay/YMSRcUPRNMxx.tgz".to_string()).unwrap();
assert!(svs1.is_tar());

let svs2 = SourceVersionSpecifier::new(
    "https://codeberg.org/libselfisekai/-/packages/npm/@a%2Fempty/0.0.1/files/1152452".to_string()).unwrap();
assert!(svs2.is_tar());
Source

pub fn is_git(&self) -> bool

Whether the SVS chooses a git repository as the source. This does not include the short-form GitHub slugs (see SourceVersionSpecifier::is_github).

§Example
let svs1 = SourceVersionSpecifier::new(
    "ssh://git@github.com/npm/node-semver.git#semver:^7.5.0".to_string()).unwrap();
assert!(svs1.is_git());

let svs2 = SourceVersionSpecifier::new(
    "https://github.com/isaacs/minimatch.git#v10.0.1".to_string()).unwrap();
assert!(svs2.is_git());
Source

pub fn is_github(&self) -> bool

Whether the SVS chooses a GitHub.com repository as the source. This includes the short-form GitHub slugs, and does not include full-formed Git URLs to github.com (for those, see SourceVersionSpecifier::is_git).

While regular Git URLs specify a protocol, in this special case a package manager can choose between Git over HTTPS, Git over SSH, and tarball URLs. See crate::Package::source to find out the real source.

§Example
let svs1 = SourceVersionSpecifier::new(
    "npm/node-semver#semver:^7.5.0".to_string()).unwrap();
assert!(svs1.is_github());

let svs2 = SourceVersionSpecifier::new(
    "github:isaacs/minimatch#v10.0.1".to_string()).unwrap();
assert!(svs2.is_github());
Source

pub fn aliased_package_name(&self) -> Option<PackageNameBorrowed<'_>>

Package name specified as aliased in the version specifier.

This is useful for a specific case: npm dependencies defined with a name alias, e.g. "lodash": "npm:@chastelock/lodash-fork@^4.1.0", which means that the package @chastelock/lodash-fork is available for import as lodash. Normally, there is no rename, and the package’s registry name (available in crate::Package::name) is used.

§Example
let svs = SourceVersionSpecifier::new(
    "npm:@chastelock/testcase@^2.1.37".to_string()).unwrap();
assert_eq!(svs.aliased_package_name().unwrap(), "@chastelock/testcase");
Source

pub fn npm_range_str(&self) -> Option<&str>

Version range specified by a dependency, as a string.

For a VersionRange object (to compare versions against), check out SourceVersionSpecifier::npm_range.

§Example
let svs1 = SourceVersionSpecifier::new(
    "4.2.x".to_string()).unwrap();
assert_eq!(svs1.npm_range_str().unwrap(), "4.2.x");

let svs2 = SourceVersionSpecifier::new(
    "npm:@chastelock/testcase@^2.1.37".to_string()).unwrap();
assert_eq!(svs2.npm_range_str().unwrap(), "^2.1.37");
Source

pub fn npm_range(&self) -> Option<VersionRange>

Version range specified by a dependency, as VersionRange object.

For a string slice, check out SourceVersionSpecifier::npm_range_str.

§Example
let svs1 = SourceVersionSpecifier::new(
    "4.2.x".to_string()).unwrap();
assert_eq!(svs1.npm_range_str().unwrap(), "4.2.x");

let svs2 = SourceVersionSpecifier::new(
    "npm:@chastelock/testcase@^2.1.37".to_string()).unwrap();
assert_eq!(svs2.npm_range_str().unwrap(), "^2.1.37");
Source

pub fn ssh_path_sep(&self) -> Option<&str>

If the dependency source is Git over SSH, this returns the separator used between the server part and the path. This is either : or /. There are quirks in support for these addresses between implementations.

§Example
let svs1 = SourceVersionSpecifier::new(
    "git@codeberg.org:selfisekai/chaste.git".to_string()).unwrap();
assert_eq!(svs1.ssh_path_sep().unwrap(), ":");

let svs2 = SourceVersionSpecifier::new(
    "git@codeberg.org:22/selfisekai/chaste.git".to_string()).unwrap();
assert_eq!(svs2.ssh_path_sep().unwrap(), "/");
Source§

impl SourceVersionSpecifier

Trait Implementations§

Source§

impl AsRef<str> for SourceVersionSpecifier

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for SourceVersionSpecifier

Source§

fn clone(&self) -> SourceVersionSpecifier

Returns a duplicate 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 SourceVersionSpecifier

Source§

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

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

impl PartialEq<str> for SourceVersionSpecifier

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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.

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<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> Same for T

Source§

type Output = T

Should always be Self
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.