guppy::graph

Enum ExternalSource

Source
#[non_exhaustive]
pub enum ExternalSource<'g> { Registry(&'g str), Git { repository: &'g str, req: GitReq<'g>, resolved: &'g str, }, }
Expand description

More information about an external source.

This provides information about whether an external dependency is a Git dependency or fetched from a registry.

Returned by PackageSource::parse_external.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Registry(&'g str)

This is a registry source, e.g. "registry+https://github.com/rust-lang/crates.io-index".

The associated data is the part of the string after the initial "registry+".

§Examples

use guppy::graph::ExternalSource;

let source = "registry+https://github.com/rust-lang/crates.io-index";
let parsed = ExternalSource::new(source).expect("this source is understood by guppy");

assert_eq!(
    parsed,
    ExternalSource::Registry("https://github.com/rust-lang/crates.io-index"),
);
§

Git

This is a Git source.

An example of a Git source string is "git+https://github.com/rust-lang/cargo.git?branch=main#0227f048fcb7c798026ede6cc20c92befc84c3a4". In this case, the Cargo.toml would have contained:

cargo = { git = "https://github.com/rust-lang/cargo.git", branch = "main" }

and the Cargo.lock would have contained:

[[package]]
name = "cargo"
version = "0.46.0"
source = "git+https://github.com/rust-lang/cargo.git?branch=main#0227f048fcb7c798026ede6cc20c92befc84c3a4
dependencies = [ ... ]

For more, see Specifying dependencies from git repositories in the Cargo book.

§Examples

use guppy::graph::{ExternalSource, GitReq};

// A branch source.
let source = "git+https://github.com/rust-lang/cargo.git?branch=main#0227f048fcb7c798026ede6cc20c92befc84c3a4";
let parsed = ExternalSource::new(source).expect("this source is understood by guppy");

assert_eq!(
    parsed,
    ExternalSource::Git {
        repository: "https://github.com/rust-lang/cargo.git",
        req: GitReq::Branch("main"),
        resolved: "0227f048fcb7c798026ede6cc20c92befc84c3a4",
    }
);

// A tag source.
let source = "git+https://github.com/rust-lang/cargo.git?tag=v0.46.0#0227f048fcb7c798026ede6cc20c92befc84c3a4";
let parsed = ExternalSource::new(source).expect("this source is understood by guppy");

assert_eq!(
    parsed,
    ExternalSource::Git {
        repository: "https://github.com/rust-lang/cargo.git",
        req: GitReq::Tag("v0.46.0"),
        resolved: "0227f048fcb7c798026ede6cc20c92befc84c3a4",
    }
);

// A revision source.
let source = "git+https://github.com/rust-lang/cargo.git?rev=0227f048fcb7c798026ede6cc20c92befc84c3a4#0227f048fcb7c798026ede6cc20c92befc84c3a4";
let parsed = ExternalSource::new(source).expect("this source is understood by guppy");

assert_eq!(
    parsed,
    ExternalSource::Git {
        repository: "https://github.com/rust-lang/cargo.git",
        req: GitReq::Rev("0227f048fcb7c798026ede6cc20c92befc84c3a4"),
        resolved: "0227f048fcb7c798026ede6cc20c92befc84c3a4",
    }
);

// A default source.
let source = "git+https://github.com/gyscos/zstd-rs.git#bc874a57298bdb500cdb5aeac5f23878b6480d0b";
let parsed = ExternalSource::new(source).expect("this source is understood by guppy");

assert_eq!(
    parsed,
    ExternalSource::Git {
        repository: "https://github.com/gyscos/zstd-rs.git",
        req: GitReq::Default,
        resolved: "bc874a57298bdb500cdb5aeac5f23878b6480d0b",
    }
);

Fields

§repository: &'g str

The repository for this Git source. For the above example, this would be "https://github.com/rust-lang/cargo.git".

§req: GitReq<'g>

The revision requested in Cargo.toml. This may be a tag, a branch or a specific revision (commit hash).

For the above example, req would be GitSource::Branch("main").

§resolved: &'g str

The resolved revision, as specified in Cargo.lock.

For the above example, resolved_hash would be "0227f048fcb7c798026ede6cc20c92befc84c3a4".

This is always a commit hash, and if req is GitReq::Rev then it is expected to be the same hash. (However, this is not verified by guppy.)

Implementations§

Source§

impl<'g> ExternalSource<'g>

Source

pub const REGISTRY_PLUS: &'static str = "registry+"

The string "registry+".

Used for matching with the Registry variant.

Source

pub const GIT_PLUS: &'static str = "git+"

The string "git+".

Used for matching with the Git variant.

Source

pub const BRANCH_EQ: &'static str = "?branch="

The string "?branch=".

Used for matching with the Git variant.

Source

pub const TAG_EQ: &'static str = "?tag="

The string "?tag=".

Used for matching with the Git variant.

Source

pub const REV_EQ: &'static str = "?rev="

The string "?rev=".

Used for matching with the Git variant.

Source

pub const CRATES_IO_URL: &'static str = "https://github.com/rust-lang/crates.io-index"

The URL for the crates.io registry.

This lacks the leading "registry+“ that’s part of the PackageSource.

Source

pub fn new(source: &'g str) -> Option<Self>

Attempts to parse the given string as an external source.

Returns None if the string could not be recognized as an external source.

Trait Implementations§

Source§

impl<'g> Clone for ExternalSource<'g>

Source§

fn clone(&self) -> ExternalSource<'g>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'g> Debug for ExternalSource<'g>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'g> Display for ExternalSource<'g>

The Display implementation for ExternalSource returns the string it was constructed from.

§Examples

use guppy::graph::{ExternalSource, GitReq};

let source = ExternalSource::Git {
    repository: "https://github.com/rust-lang/cargo.git",
    req: GitReq::Branch("main"),
    resolved: "0227f048fcb7c798026ede6cc20c92befc84c3a4",
};

assert_eq!(
    format!("{}", source),
    "git+https://github.com/rust-lang/cargo.git?branch=main#0227f048fcb7c798026ede6cc20c92befc84c3a4",
);
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'g> Hash for ExternalSource<'g>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'g> PartialEq for ExternalSource<'g>

Source§

fn eq(&self, other: &ExternalSource<'g>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'g> Copy for ExternalSource<'g>

Source§

impl<'g> Eq for ExternalSource<'g>

Source§

impl<'g> StructuralPartialEq for ExternalSource<'g>

Auto Trait Implementations§

§

impl<'g> Freeze for ExternalSource<'g>

§

impl<'g> RefUnwindSafe for ExternalSource<'g>

§

impl<'g> Send for ExternalSource<'g>

§

impl<'g> Sync for ExternalSource<'g>

§

impl<'g> Unpin for ExternalSource<'g>

§

impl<'g> UnwindSafe for ExternalSource<'g>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.