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
impl SourceVersionSpecifier
pub fn new(svs: String) -> Result<Self>
pub fn with_quirks(svs: String, quirks: QuirksMode) -> Result<Self>
Source§impl SourceVersionSpecifier
impl SourceVersionSpecifier
Sourcepub fn is_npm(&self) -> bool
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());
Sourcepub fn is_npm_tag(&self) -> bool
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());
Sourcepub fn is_tar(&self) -> bool
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());
Sourcepub fn is_git(&self) -> bool
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());
Sourcepub fn is_github(&self) -> bool
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());
Sourcepub fn aliased_package_name(&self) -> Option<PackageNameBorrowed<'_>>
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");
Sourcepub fn npm_range_str(&self) -> Option<&str>
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");
Sourcepub fn npm_range(&self) -> Option<VersionRange>
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");
Sourcepub fn ssh_path_sep(&self) -> Option<&str>
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
impl SourceVersionSpecifier
pub fn kind(&self) -> SourceVersionSpecifierKind
Trait Implementations§
Source§impl AsRef<str> for SourceVersionSpecifier
impl AsRef<str> for SourceVersionSpecifier
Source§impl Clone for SourceVersionSpecifier
impl Clone for SourceVersionSpecifier
Source§fn clone(&self) -> SourceVersionSpecifier
fn clone(&self) -> SourceVersionSpecifier
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more