pub fn kv_parse(kv: &str) -> Result<String, crate::Error> {
    let mut iter = kv.split('&');

    let mut result = serde_json::Map::new();

    loop {
        match iter.next() {
            Some(inner_kv) => {
                if inner_kv.matches('=').count() != 1 {
                    return Err(crate::Error::InvalidKVPair);
                }

                let mut inner_iter = inner_kv.split('=');

                let left = inner_iter.next().unwrap();
                let right = inner_iter.next().unwrap();

                result.insert(
                    left.to_string(),
                    match right.parse::<i64>() {
                        Ok(v) => serde_json::Value::Number(serde_json::Number::from(v)),
                        Err(_) => serde_json::Value::String(right.to_string()),
                    },
                );
            }
            None => break,
        };
    }

    Ok(serde_json::to_string(&result).unwrap())
}
/// decoding for key-value pairs
///
/// Solution for problem 5 from set 2: <https://cryptopals.com/sets/2/challenges/13>
decoding for key-value pairs
Solution for problem 5 from set 2.
decoding for key - value pairs Solution for problem 5 from set 2 .
pub fn kv_parse(kv: &str) -> Result<String, crate::Error> {
    let mut iter = kv.split('&');
    let mut result = serde_json::Map::new();
    loop {
        match iter.next() {
            Some(inner_kv) => {
                if inner_kv.matches('=').count() != 1 {
                    return Err(crate::Error::InvalidKVPair);
                }
                let mut inner_iter = inner_kv.split('=');
                let left = inner_iter.next().unwrap();
                let right = inner_iter.next().unwrap();
                result.insert(
                    left.to_string(),
                    match right.parse::<i64>() {
                        Ok(v) => serde_json::Value::Number(serde_json::Number::from(v)),
                        Err(_) => serde_json::Value::String(right.to_string()),
                    },
                );
            }
            None => break,
        };
    }
    Ok(serde_json::to_string(&result).unwrap())
}
pub fn kv_parse ( kv : & str ) -> Result < String , crate :: Error > { let mut iter = kv . split ( '&' ) ; let mut result = serde_json :: Map :: new ( ) ; loop { match iter . next ( ) { Some ( inner_kv ) => { if inner_kv . matches ( '=' ) . count ( ) != 1 { return Err ( crate :: Error :: InvalidKVPair ) ; } let mut inner_iter = inner_kv . split ( '=' ) ; let left = inner_iter . next ( ) . unwrap ( ) ; let right = inner_iter . next ( ) . unwrap ( ) ; result . insert ( left . to_string ( ) , match right . parse :: < i64 > ( ) { Ok ( v ) => serde_json :: Value :: Number ( serde_json :: Number :: from ( v ) ) , Err ( _ ) => serde_json :: Value :: String ( right . to_string ( ) ) , } , ) ; } None => break , } ; } Ok ( serde_json :: to_string ( & result ) . unwrap ( ) ) }
decoding for key-value pairs
Solution for problem 5 from set 2: <https://cryptopals.com/sets/2/challenges/13>
decoding for key - value pairs Solution for problem 5 from set 2 : <https : // cryptopals . com / sets / 2 / challenges / 13 >
kv
&str