pub fn extract_literal_string<I>(
    first_arg: &TokenTree,
    rest_of_stream: &mut I,
) -> Result<Option<String>, String>
where
    I: Iterator<Item = TokenTree>,
{
    match first_arg {
        TokenTree::Ident(ident) => {
            if ["true", "false", "null"].contains(&&ident.to_string()[..]) {
                Ok(Some(ident.to_string()))
            } else {
                Ok(None)
            }
        }
        TokenTree::Literal(literal) => Ok(Some(literal.to_string())),
        TokenTree::Punct(punct) if punct.as_char() == '-' => {
            match rest_of_stream.next() {
                Some(TokenTree::Literal(literal)) => {
                    Ok(Some(format!("{}{}", punct.as_char(), literal.to_string())))
                }
                None => Ok(None),
                // Must error instead of handling the tokens using default
                // behavior since `stream_iter` has advanced.
                Some(other) => Err(format!(
                    "{}{:?} is not a valid literal",
                    punct.as_char(),
                    other
                )),
            }
        }
        _ => Ok(None),
    }
}
/// If the stream starts with a sequence of tokens that can be parsed as a datum,
/// return those tokens as one string.
///
/// Sequences of tokens that can be parsed as a datum:
/// * A Literal token, which is anything in quotations or a positive number
/// * An null, false, or true Ident token
/// * Punct(-) + a literal token
///
/// If the stream starts with a sequence of tokens that can be parsed as a
/// datum, 1) returns Ok(Some(..)) 2) advances the stream to the first token
/// that is not part of the sequence.
/// If the stream does not start with tokens that can be parsed as a datum:
/// * Return Ok(None) if `rest_of_stream` has not been advanced.
/// * Returns Err(..) otherwise.
If the stream starts with a sequence of tokens that can be parsed as a datum,
return those tokens as one string.

Sequences of tokens that can be parsed as a datum:
A Literal token, which is anything in quotations or a positive number
An null, false, or true Ident token
Punct(-) + a literal token

If the stream starts with a sequence of tokens that can be parsed as a
datum, 1) returns Ok(Some(..)) 2) advances the stream to the first token
that is not part of the sequence.
If the stream does not start with tokens that can be parsed as a datum:
Return Ok(None) if `rest_of_stream` has not been advanced.
Returns Err(..) otherwise.
If the stream starts with a sequence of tokens that can be parsed as a datum return those tokens as one string . Sequences of tokens that can be parsed as a datum : A Literal token which is anything in quotations or a positive number An null false or true Ident token Punct ( - ) + a literal token If the stream starts with a sequence of tokens that can be parsed as a datum 1 ) returns Ok ( Some ( .. )) 2 ) advances the stream to the first token that is not part of the sequence . If the stream does not start with tokens that can be parsed as a datum : Return Ok ( None ) if ` rest_of_stream ` has not been advanced . Returns Err ( .. ) otherwise .
pub fn extract_literal_string<I>(
    first_arg: &TokenTree,
    rest_of_stream: &mut I,
) -> Result<Option<String>, String>
where
    I: Iterator<Item = TokenTree>,
{
    match first_arg {
        TokenTree::Ident(ident) => {
            if ["true", "false", "null"].contains(&&ident.to_string()[..]) {
                Ok(Some(ident.to_string()))
            } else {
                Ok(None)
            }
        }
        TokenTree::Literal(literal) => Ok(Some(literal.to_string())),
        TokenTree::Punct(punct) if punct.as_char() == '-' => {
            match rest_of_stream.next() {
                Some(TokenTree::Literal(literal)) => {
                    Ok(Some(format!("{}{}", punct.as_char(), literal.to_string())))
                }
                None => Ok(None),
                // Must error instead of handling the tokens using default
                // behavior since `stream_iter` has advanced.
                Some(other) => Err(format!(
                    "{}{:?} is not a valid literal",
                    punct.as_char(),
                    other
                )),
            }
        }
        _ => Ok(None),
    }
}
pub fn extract_literal_string < I > ( first_arg : & TokenTree , rest_of_stream : & mut I , ) -> Result < Option < String > , String > where I : Iterator < Item = TokenTree > , { match first_arg { TokenTree :: Ident ( ident ) => { if [ " " , " " , " " ] . contains ( & & ident . to_string ( ) [ .. ] ) { Ok ( Some ( ident . to_string ( ) ) ) } else { Ok ( None ) } } TokenTree :: Literal ( literal ) => Ok ( Some ( literal . to_string ( ) ) ) , TokenTree :: Punct ( punct ) if punct . as_char ( ) == '-' => { match rest_of_stream . next ( ) { Some ( TokenTree :: Literal ( literal ) ) => { Ok ( Some ( format ! ( " " punct as_char ( ) literal to_string ( ) ) ) ) } None => Ok ( None ) , // Must error instead of handling the tokens using default // behavior since `stream_iter` has advanced. Some ( other ) => Err ( format ! ( " " punct as_char ( ) other ) ) , } } _ => Ok ( None ) , } }
If the stream starts with a sequence of tokens that can be parsed as a datum,
return those tokens as one string.
If the stream starts with a sequence of tokens that can be parsed as a datum return those tokens as one string .
first_arg
&TokenTree
rest_of_stream
&mut I
first_arg
&TokenTree
rest_of_stream
&mut I