Function parse_ref

Source
pub fn parse_ref<T>(s: &str) -> Result<(Option<T>, Qualified<'_>), RefError>
where T: FromStr, <T as FromStr>::Err: Error + Send + Sync + 'static,
Expand description

Parse a format::Qualified reference string. It will optionally return the namespace, if present.

The qualified form could be of the form: refs/heads/main, refs/tags/v1.0, etc.

The namespace returned is the path component that is after refs/namespaces, e.g. in the reference below, the segment is z6MkvUJtYD9dHDJfpevWRT98mzDDpdAtmUjwyDSkyqksUr7C:

refs/namespaces/z6MkvUJtYD9dHDJfpevWRT98mzDDpdAtmUjwyDSkyqksUr7C/refs/heads/main

The T can be specified when calling the function. For example, if you wanted to parse the namespace as a PublicKey, then you would the function like so, parse_ref::<PublicKey>(s).