GitUrl

Struct GitUrl 

Source
pub struct GitUrl { /* private fields */ }
Expand description

Represents a parsed Git repository url

GitUrl is an input url used by git. Parsing of the url inspired by rfc3986, but does not strictly cover the spec Optional, but by default, uses the url crate to perform a final validation of the parsing effort

Implementations§

Source§

impl GitUrl

Source

pub fn port(&self) -> Option<u16>

The port number of the repo host, if specified

Source

pub fn print_scheme(&self) -> bool

If we should print scheme:// from input or derived during parsing

Source

pub fn hint(&self) -> GitUrlParseHint

Pattern style of url derived during parsing

Source§

impl GitUrl

Source

pub fn scheme(&self) -> Option<&str>

scheme name (i.e. scheme://)

Source

pub fn user(&self) -> Option<&str>

user name userinfo

Source

pub fn password(&self) -> Option<&str>

password userinfo provided with user (i.e. user:password@…)

Source

pub fn host(&self) -> Option<&str>

The hostname or IP of the repo host

Source

pub fn path(&self) -> &str

File or network path to repo

Source

pub fn trim_auth(&self) -> GitUrl

Returns GitUrl after removing all user info values

Source

pub fn parse(input: &str) -> Result<Self, GitUrlParseError>

Returns a Result<GitUrl> after parsing input for metadata

let http_url = GitUrl::parse("https://github.com/tjtelan/git-url-parse-rs.git")?;
let ssh_url = GitUrl::parse("git@github.com:tjtelan/git-url-parse-rs.git")?;
Source

pub fn parse_to_url(input: &str) -> Result<Url, GitUrlParseError>

Normalize input into form that can be used by Url::parse

use git_url_parse::GitUrl;
#[cfg(feature = "url")]
use url::Url;

fn main() -> Result<(), git_url_parse::GitUrlParseError> {
    let ssh_url = GitUrl::parse_to_url("git@github.com:tjtelan/git-url-parse-rs.git")?;

    assert_eq!(ssh_url.scheme(), "ssh");
    assert_eq!(ssh_url.username(), "git");
    assert_eq!(ssh_url.host_str(), Some("github.com"));
    assert_eq!(ssh_url.path(), "/tjtelan/git-url-parse-rs.git");
    Ok(())
}
Source

pub fn provider_info<T>(&self) -> Result<T, GitUrlParseError>

use git_url_parse::GitUrl;
use git_url_parse::types::provider::GenericProvider;

let ssh_url = GitUrl::parse("git@github.com:tjtelan/git-url-parse-rs.git")?;
let provider : GenericProvider = ssh_url.provider_info()?;

Trait Implementations§

Source§

impl Clone for GitUrl

Source§

fn clone(&self) -> GitUrl

Returns a duplicate 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 Debug for GitUrl

Source§

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

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

impl Default for GitUrl

Source§

fn default() -> GitUrl

Returns the “default value” for a type. Read more
Source§

impl Display for GitUrl

Build the printable GitUrl from its components

Source§

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

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

impl GitProvider<GitUrl, GitUrlParseError> for AzureDevOpsProvider

Source§

fn from_git_url(url: &GitUrl) -> Result<Self, GitUrlParseError>

Trait method called by GitUrl::provider_info() Read more
Source§

impl GitProvider<GitUrl, GitUrlParseError> for GenericProvider

Source§

fn from_git_url(url: &GitUrl) -> Result<Self, GitUrlParseError>

Trait method called by GitUrl::provider_info() Read more
Source§

impl GitProvider<GitUrl, GitUrlParseError> for GitLabProvider

Source§

fn from_git_url(url: &GitUrl) -> Result<Self, GitUrlParseError>

Trait method called by GitUrl::provider_info() Read more
Source§

impl PartialEq for GitUrl

Source§

fn eq(&self, other: &GitUrl) -> 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 TryFrom<&GitUrl> for Url

Source§

type Error = ParseError

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

fn try_from(value: &GitUrl) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&Url> for GitUrl

Source§

type Error = GitUrlParseError

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

fn try_from(value: &Url) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<GitUrl> for Url

Source§

type Error = ParseError

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

fn try_from(value: GitUrl) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Url> for GitUrl

Source§

type Error = GitUrlParseError

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

fn try_from(value: Url) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for GitUrl

Source§

impl StructuralPartialEq for GitUrl

Auto Trait Implementations§

§

impl Freeze for GitUrl

§

impl RefUnwindSafe for GitUrl

§

impl Send for GitUrl

§

impl Sync for GitUrl

§

impl Unpin for GitUrl

§

impl UnwindSafe for GitUrl

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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§

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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,