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§
source§impl 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![
"https://crates.io/foo",
"https://crates.io/foo#1.2.3",
"https://crates.io/foo#bar:1.2.3",
"https://crates.io/foo#bar@1.2.3",
"foo",
"foo:1.2.3",
"foo@1.2.3",
];
for spec in specs {
assert!(PackageIdSpec::parse(spec).is_ok());
}
sourcepub fn query_str<I>(spec: &str, i: I) -> CargoResult<PackageId>where
I: IntoIterator<Item = PackageId>,
pub fn query_str<I>(spec: &str, i: I) -> CargoResult<PackageId>where I: IntoIterator<Item = 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) -> InternedString
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<I>(&self, i: I) -> CargoResult<PackageId>where
I: IntoIterator<Item = PackageId>,
pub fn query<I>(&self, i: I) -> CargoResult<PackageId>where I: IntoIterator<Item = 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§
source§impl Clone for PackageIdSpec
impl Clone for PackageIdSpec
source§fn clone(&self) -> PackageIdSpec
fn clone(&self) -> PackageIdSpec
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PackageIdSpec
impl Debug for PackageIdSpec
source§impl<'de> Deserialize<'de> for PackageIdSpec
impl<'de> Deserialize<'de> for PackageIdSpec
source§fn 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
source§impl Display for PackageIdSpec
impl Display for PackageIdSpec
source§impl Hash for PackageIdSpec
impl Hash for PackageIdSpec
source§impl Ord for PackageIdSpec
impl Ord for PackageIdSpec
source§fn cmp(&self, other: &PackageIdSpec) -> Ordering
fn cmp(&self, other: &PackageIdSpec) -> Ordering
1.21.0 · source§fn 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
source§impl PartialEq<PackageIdSpec> for PackageIdSpec
impl PartialEq<PackageIdSpec> for PackageIdSpec
source§fn eq(&self, other: &PackageIdSpec) -> bool
fn eq(&self, other: &PackageIdSpec) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<PackageIdSpec> for PackageIdSpec
impl PartialOrd<PackageIdSpec> for PackageIdSpec
source§fn partial_cmp(&self, other: &PackageIdSpec) -> Option<Ordering>
fn partial_cmp(&self, other: &PackageIdSpec) -> Option<Ordering>
1.0.0 · source§fn 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 moresource§impl 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§
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
Mutably borrows from an owned value. Read more
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more