Struct cargo::core::PackageIdSpec
source · pub struct PackageIdSpec {
name: String,
version: Option<PartialVersion>,
url: Option<Url>,
kind: Option<SourceKind>,
}
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: String
§version: Option<PartialVersion>
§url: Option<Url>
§kind: Option<SourceKind>
Implementations§
source§impl PackageIdSpec
impl PackageIdSpec
pub fn new(name: String) -> PackageIdSpec
pub fn with_version(self, version: PartialVersion) -> PackageIdSpec
pub fn with_url(self, url: Url) -> PackageIdSpec
pub fn with_kind(self, kind: SourceKind) -> PackageIdSpec
sourcepub fn parse(spec: &str) -> Result<PackageIdSpec, PackageIdSpecError>
pub fn parse(spec: &str) -> Result<PackageIdSpec, PackageIdSpecError>
Parses a spec string and returns a PackageIdSpec
if the string was valid.
§Examples
Some examples of valid strings
use cargo_util_schemas::core::PackageIdSpec;
let specs = vec![
"foo",
"foo@1.4",
"foo@1.4.3",
"foo:1.2.3",
"https://github.com/rust-lang/crates.io-index#foo",
"https://github.com/rust-lang/crates.io-index#foo@1.4.3",
"ssh://git@github.com/rust-lang/foo.git#foo@1.4.3",
"file:///path/to/my/project/foo",
"file:///path/to/my/project/foo#1.1.8"
];
for spec in specs {
assert!(PackageIdSpec::parse(spec).is_ok());
}
pub fn name(&self) -> &str
pub fn partial_version(&self) -> Option<&PartialVersion>
pub fn url(&self) -> Option<&Url>
pub fn set_url(&mut self, url: Url)
pub fn kind(&self) -> Option<&SourceKind>
pub fn set_kind(&mut self, kind: SourceKind)
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 as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
d: D,
) -> Result<PackageIdSpec, <D as Deserializer<'de>>::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 PackageIdSpecQuery for PackageIdSpec
impl PackageIdSpecQuery for PackageIdSpec
source§fn query_str<I>(spec: &str, i: I) -> CargoResult<PackageId>where
I: IntoIterator<Item = PackageId>,
fn query_str<I>(spec: &str, i: I) -> CargoResult<PackageId>where
I: IntoIterator<Item = PackageId>,
Roughly equivalent to
PackageIdSpec::parse(spec)?.query(i)
source§fn matches(&self, package_id: PackageId) -> bool
fn matches(&self, package_id: PackageId) -> bool
Checks whether the given
PackageId
matches the PackageIdSpec
.source§fn query<I>(&self, i: I) -> CargoResult<PackageId>where
I: IntoIterator<Item = PackageId>,
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.source§impl PartialEq for PackageIdSpec
impl PartialEq for PackageIdSpec
source§impl PartialOrd for PackageIdSpec
impl PartialOrd for PackageIdSpec
source§impl Serialize for PackageIdSpec
impl Serialize for PackageIdSpec
source§fn serialize<S>(
&self,
s: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
s: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for PackageIdSpec
impl StructuralPartialEq for PackageIdSpec
Auto Trait Implementations§
impl Freeze for PackageIdSpec
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§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>,
§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: 200 bytes