Struct cargo::core::PackageIdSpec
source · pub struct PackageIdSpec {
name: InternedString,
version: Option<PartialVersion>,
url: Option<Url>,
}
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.
Fields§
§name: InternedString
§version: Option<PartialVersion>
§url: Option<Url>
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 PartialVersion
and Url
fields filled in.
sourcefn from_url(url: Url) -> CargoResult<PackageIdSpec>
fn from_url(url: Url) -> CargoResult<PackageIdSpec>
Tries to convert a valid Url
to a PackageIdSpec
.
pub fn name(&self) -> InternedString
pub fn partial_version(&self) -> Option<&PartialVersion>
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
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
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,
source§impl PartialEq<PackageIdSpec> for PackageIdSpec
impl PartialEq<PackageIdSpec> for PackageIdSpec
source§fn eq(&self, other: &PackageIdSpec) -> bool
fn eq(&self, other: &PackageIdSpec) -> bool
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
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
§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
§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
key
and return true
if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Serialize for Twhere
T: Serialize + ?Sized,
impl<T> Serialize for Twhere T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,
source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 160 bytes