fn from_str(refstr: &str) -> Result<RawReference> {
        // TODO: leverage Pest for better error messages

        let mut path_str = None;
        let mut domain_str = None;
        let mut tag_str = None;
        let mut digest_str = None;

        let refstr_p = PestReferenceParser::parse(Rule::refstr, refstr)
            .map_err(Error::Parse)?
            // top-level rules are guaranteed to have a single Pair
            .next()
            .unwrap()
            // refstr rule _must_ parse into a single reference rule
            .into_inner()
            .next()
            .unwrap();

        // this nastly little mess of code traverses the parse tree to extract
        // the tokes we care about
        for ref_p in refstr_p.into_inner() {
            let val = ref_p.as_str().to_string();
            match ref_p.as_rule() {
                Rule::name => {
                    for name_p in ref_p.into_inner() {
                        let val = name_p.as_str().to_string();
                        match name_p.as_rule() {
                            Rule::domain => domain_str = Some(val),
                            Rule::path => path_str = Some(val),
                            _ => unreachable!(),
                        }
                    }
                }
                Rule::tag => tag_str = Some(val),
                Rule::digest => digest_str = Some(val),
                _ => unreachable!(),
            }
        }

        // ok to unwrap, as a path must be present for the string to parse
        let path = path_str.unwrap();

        if path.len() + domain_str.as_ref().map_or(0, |s| s.len() + 1) > 255 {
            return Err(Error::NameTooLong);
        }

        let mut digest = None;
        if let Some(digest_str) = digest_str {
            digest = Some(digest_str.parse().map_err(Error::Digest)?);
        }

        Ok(RawReference {
            path,
            domain: domain_str,
            tag: tag_str,
            digest,
        })
    }
/// Parse a raw object reference str into a [RawReference], returning
/// an Error if the refstr doesn't conform to the grammar, or violates
/// some non-syntactic rule (e.g: invalid digest)
///
/// For a full string grammar, see
/// github.com/docker/distribution/reference/reference.go
Parse a raw object reference str into a [RawReference], returning
an Error if the refstr doesn't conform to the grammar, or violates
some non-syntactic rule


Parse a raw object reference str into a [ RawReference ] returning an Error if the refstr doesn ' t conform to the grammar or violates some non - syntactic rule
fn from_str(refstr: &str) -> Result<RawReference> {
        // TODO: leverage Pest for better error messages
        let mut path_str = None;
        let mut domain_str = None;
        let mut tag_str = None;
        let mut digest_str = None;
        let refstr_p = PestReferenceParser::parse(Rule::refstr, refstr)
            .map_err(Error::Parse)?
            // top-level rules are guaranteed to have a single Pair
            .next()
            .unwrap()
            // refstr rule _must_ parse into a single reference rule
            .into_inner()
            .next()
            .unwrap();
        // this nastly little mess of code traverses the parse tree to extract
        // the tokes we care about
        for ref_p in refstr_p.into_inner() {
            let val = ref_p.as_str().to_string();
            match ref_p.as_rule() {
                Rule::name => {
                    for name_p in ref_p.into_inner() {
                        let val = name_p.as_str().to_string();
                        match name_p.as_rule() {
                            Rule::domain => domain_str = Some(val),
                            Rule::path => path_str = Some(val),
                            _ => unreachable!(),
                        }
                    }
                }
                Rule::tag => tag_str = Some(val),
                Rule::digest => digest_str = Some(val),
                _ => unreachable!(),
            }
        }
        // ok to unwrap, as a path must be present for the string to parse
        let path = path_str.unwrap();
        if path.len() + domain_str.as_ref().map_or(0, |s| s.len() + 1) > 255 {
            return Err(Error::NameTooLong);
        }
        let mut digest = None;
        if let Some(digest_str) = digest_str {
            digest = Some(digest_str.parse().map_err(Error::Digest)?);
        }
        Ok(RawReference {
            path,
            domain: domain_str,
            tag: tag_str,
            digest,
        })
    }
fn from_str ( refstr : & str ) -> Result < RawReference > { // TODO: leverage Pest for better error messages let mut path_str = None ; let mut domain_str = None ; let mut tag_str = None ; let mut digest_str = None ; let refstr_p = PestReferenceParser :: parse ( Rule :: refstr , refstr ) . map_err ( Error :: Parse ) ? // top-level rules are guaranteed to have a single Pair . next ( ) . unwrap ( ) // refstr rule _must_ parse into a single reference rule . into_inner ( ) . next ( ) . unwrap ( ) ; // this nastly little mess of code traverses the parse tree to extract // the tokes we care about for ref_p in refstr_p . into_inner ( ) { let val = ref_p . as_str ( ) . to_string ( ) ; match ref_p . as_rule ( ) { Rule :: name => { for name_p in ref_p . into_inner ( ) { let val = name_p . as_str ( ) . to_string ( ) ; match name_p . as_rule ( ) { Rule :: domain => domain_str = Some ( val ) , Rule :: path => path_str = Some ( val ) , _ => unreachable ! ( ) , } } } Rule :: tag => tag_str = Some ( val ) , Rule :: digest => digest_str = Some ( val ) , _ => unreachable ! ( ) , } } // ok to unwrap, as a path must be present for the string to parse let path = path_str . unwrap ( ) ; if path . len ( ) + domain_str . as_ref ( ) . map_or ( 0 , | s | s . len ( ) + 1 ) > 255 { return Err ( Error :: NameTooLong ) ; } let mut digest = None ; if let Some ( digest_str ) = digest_str { digest = Some ( digest_str . parse ( ) . map_err ( Error :: Digest ) ? ) ; } Ok ( RawReference { path , domain : domain_str , tag : tag_str , digest , } ) }
Parse a raw object reference str into a [RawReference], returning
an Error if the refstr doesn't conform to the grammar, or violates
some non-syntactic rule (e.g: invalid digest)
Parse a raw object reference str into a [ RawReference ] returning an Error if the refstr doesn ' t conform to the grammar or violates some non - syntactic rule ( e . g : invalid digest )
refstr
&str
refstr
&str