Struct cargo::core::PackageIdSpec
source · pub struct PackageIdSpec { /* private fields */ }
Expand description
Some or all of the data required to identify a package:
- the package name (a
String
, required) - the package version (a
Version
, optional) - the package source (a
Url
, optional)
If any of the optional fields are omitted, then the package id may be ambiguous, there may be more than one package/version/url combo that will match. However, often just the name is sufficient to uniquely define a package id.
Implementations
sourceimpl PackageIdSpec
impl PackageIdSpec
sourcepub fn parse(spec: &str) -> CargoResult<PackageIdSpec>
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec>
Parses a spec string and returns a PackageIdSpec
if the string was valid.
Examples
Some examples of valid strings
use cargo::core::PackageIdSpec;
let specs = vec![
"http://crates.io/foo#1.2.3",
"http://crates.io/foo#bar:1.2.3",
"crates.io/foo",
"crates.io/foo#1.2.3",
"crates.io/foo#bar",
"crates.io/foo#bar:1.2.3",
"foo",
"foo:1.2.3",
];
for spec in specs {
assert!(PackageIdSpec::parse(spec).is_ok());
}
sourcepub fn query_str<'a, I>(spec: &str, i: I) -> CargoResult<&'a PackageId>where
I: IntoIterator<Item = &'a PackageId>,
pub fn query_str<'a, I>(spec: &str, i: I) -> CargoResult<&'a PackageId>where
I: IntoIterator<Item = &'a PackageId>,
Roughly equivalent to PackageIdSpec::parse(spec)?.query(i)
sourcepub fn from_package_id(package_id: &PackageId) -> PackageIdSpec
pub fn from_package_id(package_id: &PackageId) -> PackageIdSpec
Convert a PackageId
to a PackageIdSpec
, which will have both the Version
and Url
fields filled in.
pub fn name(&self) -> &str
pub fn version(&self) -> Option<&Version>
pub fn url(&self) -> Option<&Url>
pub fn set_url(&mut self, url: Url)
sourcepub fn matches(&self, package_id: &PackageId) -> bool
pub fn matches(&self, package_id: &PackageId) -> bool
Checks whether the given PackageId
matches the PackageIdSpec
.
sourcepub fn query<'a, I>(&self, i: I) -> CargoResult<&'a PackageId>where
I: IntoIterator<Item = &'a PackageId>,
pub fn query<'a, I>(&self, i: I) -> CargoResult<&'a PackageId>where
I: IntoIterator<Item = &'a PackageId>,
Checks a list of PackageId
s to find 1 that matches this PackageIdSpec
. If 0, 2, or
more are found, then this returns an error.
Trait Implementations
sourceimpl Clone for PackageIdSpec
impl Clone for PackageIdSpec
sourcefn clone(&self) -> PackageIdSpec
fn clone(&self) -> PackageIdSpec
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for PackageIdSpec
impl Debug for PackageIdSpec
sourceimpl<'de> Deserialize<'de> for PackageIdSpec
impl<'de> Deserialize<'de> for PackageIdSpec
sourcefn deserialize<D>(d: D) -> Result<PackageIdSpec, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<PackageIdSpec, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Display for PackageIdSpec
impl Display for PackageIdSpec
sourceimpl Hash for PackageIdSpec
impl Hash for PackageIdSpec
sourceimpl Ord for PackageIdSpec
impl Ord for PackageIdSpec
sourcefn cmp(&self, other: &PackageIdSpec) -> Ordering
fn cmp(&self, other: &PackageIdSpec) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<PackageIdSpec> for PackageIdSpec
impl PartialEq<PackageIdSpec> for PackageIdSpec
sourcefn eq(&self, other: &PackageIdSpec) -> bool
fn eq(&self, other: &PackageIdSpec) -> bool
sourceimpl PartialOrd<PackageIdSpec> for PackageIdSpec
impl PartialOrd<PackageIdSpec> for PackageIdSpec
sourcefn partial_cmp(&self, other: &PackageIdSpec) -> Option<Ordering>
fn partial_cmp(&self, other: &PackageIdSpec) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresourceimpl Serialize for PackageIdSpec
impl Serialize for PackageIdSpec
impl Eq for PackageIdSpec
impl StructuralEq for PackageIdSpec
impl StructuralPartialEq for PackageIdSpec
Auto Trait Implementations
impl RefUnwindSafe for PackageIdSpec
impl Send for PackageIdSpec
impl Sync for PackageIdSpec
impl Unpin for PackageIdSpec
impl UnwindSafe for PackageIdSpec
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more