pub fn from_url(string: &str) -> Result<Self, Error> {
        let mut parts = string.splitn(2, '+');
        let kind = parts.next().unwrap();
        let url = parts
            .next()
            .ok_or_else(|| format_err!(ErrorKind::Parse, "invalid source `{}`", string))?;

        match kind {
            "git" => {
                let mut url = url.into_url()?;
                let mut reference = GitReference::Branch(DEFAULT_BRANCH.to_string());
                for (k, v) in url.query_pairs() {
                    match &k[..] {
                        // Map older 'ref' to branch.
                        "branch" | "ref" => reference = GitReference::Branch(v.into_owned()),

                        "rev" => reference = GitReference::Rev(v.into_owned()),
                        "tag" => reference = GitReference::Tag(v.into_owned()),
                        _ => {}
                    }
                }
                let precise = url.fragment().map(|s| s.to_owned());
                url.set_fragment(None);
                url.set_query(None);
                Ok(Self::for_git(&url, reference)?.with_precise(precise))
            }
            "registry" => {
                let url = url.into_url()?;
                Ok(SourceId::new(SourceKind::Registry, url)?
                    .with_precise(Some("locked".to_string())))
            }
            "path" => Self::new(SourceKind::Path, url.into_url()?),
            kind => fail!(ErrorKind::Parse, "unsupported source protocol: {}", kind),
        }
    }
/// Parses a source URL and returns the corresponding ID.
///
/// ## Example
///
/// ```
/// use cargo_lock::SourceId;
/// SourceId::from_url("git+https://github.com/alexcrichton/\
///                     libssh2-static-sys#80e71a3021618eb05\
///                     656c58fb7c5ef5f12bc747f");
/// ```
Parses a source URL and returns the corresponding ID.
Parses a source URL and returns the corresponding ID .
pub fn from_url(string: &str) -> Result<Self, Error> {
        let mut parts = string.splitn(2, '+');
        let kind = parts.next().unwrap();
        let url = parts
            .next()
            .ok_or_else(|| format_err!(ErrorKind::Parse, "invalid source `{}`", string))?;
        match kind {
            "git" => {
                let mut url = url.into_url()?;
                let mut reference = GitReference::Branch(DEFAULT_BRANCH.to_string());
                for (k, v) in url.query_pairs() {
                    match &k[..] {
                        // Map older 'ref' to branch.
                        "branch" | "ref" => reference = GitReference::Branch(v.into_owned()),
                        "rev" => reference = GitReference::Rev(v.into_owned()),
                        "tag" => reference = GitReference::Tag(v.into_owned()),
                        _ => {}
                    }
                }
                let precise = url.fragment().map(|s| s.to_owned());
                url.set_fragment(None);
                url.set_query(None);
                Ok(Self::for_git(&url, reference)?.with_precise(precise))
            }
            "registry" => {
                let url = url.into_url()?;
                Ok(SourceId::new(SourceKind::Registry, url)?
                    .with_precise(Some("locked".to_string())))
            }
            "path" => Self::new(SourceKind::Path, url.into_url()?),
            kind => fail!(ErrorKind::Parse, "unsupported source protocol: {}", kind),
        }
    }
pub fn from_url ( string : & str ) -> Result < Self , Error > { let mut parts = string . splitn ( 2 , '+' ) ; let kind = parts . next ( ) . unwrap ( ) ; let url = parts . next ( ) . ok_or_else ( | | format_err ! ( ErrorKind Parse " " string ) ) ? ; match kind { " " => { let mut url = url . into_url ( ) ? ; let mut reference = GitReference :: Branch ( DEFAULT_BRANCH . to_string ( ) ) ; for ( k , v ) in url . query_pairs ( ) { match & k [ .. ] { // Map older 'ref' to branch. " " | " " => reference = GitReference :: Branch ( v . into_owned ( ) ) , " " => reference = GitReference :: Rev ( v . into_owned ( ) ) , " " => reference = GitReference :: Tag ( v . into_owned ( ) ) , _ => { } } } let precise = url . fragment ( ) . map ( | s | s . to_owned ( ) ) ; url . set_fragment ( None ) ; url . set_query ( None ) ; Ok ( Self :: for_git ( & url , reference ) ? . with_precise ( precise ) ) } " " => { let url = url . into_url ( ) ? ; Ok ( SourceId :: new ( SourceKind :: Registry , url ) ? . with_precise ( Some ( " " . to_string ( ) ) ) ) } " " => Self :: new ( SourceKind :: Path , url . into_url ( ) ? ) , kind => fail ! ( ErrorKind Parse " " kind ) , } }
Parses a source URL and returns the corresponding ID.
Parses a source URL and returns the corresponding ID .
string
&str
string
&str
example
None