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) -> Self
pub fn with_version(self, version: PartialVersion) -> Self
pub fn with_url(self, url: Url) -> Self
pub fn with_kind(self, kind: SourceKind) -> Self
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());
}
Sourcefn from_url(url: Url) -> Result<PackageIdSpec, PackageIdSpecError>
fn from_url(url: Url) -> Result<PackageIdSpec, PackageIdSpecError>
Tries to convert a valid Url
to a PackageIdSpec
.
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::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 for PackageIdSpec
impl PartialEq for PackageIdSpec
Source§impl PartialOrd for PackageIdSpec
impl PartialOrd for PackageIdSpec
Source§impl Serialize for PackageIdSpec
impl Serialize for PackageIdSpec
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.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> 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