pub fn from_json(json: &Json, pairs: &[(&str, &str)]) -> Result<Key, ()> {
        debug_assert!(pairs.iter().zip(pairs.iter().skip(1))
            .all(|(&(a, _), &(b, _))| a < b));
        if let &Json::Object(ref obj) = json {
            let btree: &BTreeMap<_, _> = obj;  // assert it's BTree
                                               // because we care about order
            let mut errors = 0;
            let num = btree.len() + pairs.len() -
                pairs.iter().filter(|&&(x, _)| btree.contains_key(x)).count();
            let res = Key::from_iter(Merge(num,
                pairs.iter().cloned().peekable(),
                btree.iter().map(|(ref k, v)| {
                    match v {
                        &Json::String(ref val) => {
                            (&k[..], &val[..])
                        }
                        // TODO(tailhook) probably support numbers
                        _ => {
                            errors += 1;
                            (&k[..], "")
                        }
                    }
                }).peekable(),
                PhantomData,
                ));
            if errors > 0 {
                return Err(());
            }
            return Ok(res);
        } else {
            return Err(());
        }
    }
/// Creates a key json object with additional pairs added
///
/// Note pairs should be sorted
Creates a key json object with additional pairs added
Note pairs should be sorted
Creates a key json object with additional pairs added Note pairs should be sorted
pub fn from_json(json: &Json, pairs: &[(&str, &str)]) -> Result<Key, ()> {
        debug_assert!(pairs.iter().zip(pairs.iter().skip(1))
            .all(|(&(a, _), &(b, _))| a < b));
        if let &Json::Object(ref obj) = json {
            let btree: &BTreeMap<_, _> = obj;  // assert it's BTree
                                               // because we care about order
            let mut errors = 0;
            let num = btree.len() + pairs.len() -
                pairs.iter().filter(|&&(x, _)| btree.contains_key(x)).count();
            let res = Key::from_iter(Merge(num,
                pairs.iter().cloned().peekable(),
                btree.iter().map(|(ref k, v)| {
                    match v {
                        &Json::String(ref val) => {
                            (&k[..], &val[..])
                        }
                        // TODO(tailhook) probably support numbers
                        _ => {
                            errors += 1;
                            (&k[..], "")
                        }
                    }
                }).peekable(),
                PhantomData,
                ));
            if errors > 0 {
                return Err(());
            }
            return Ok(res);
        } else {
            return Err(());
        }
    }
pub fn from_json ( json : & Json , pairs : & [ ( & str , & str ) ] ) -> Result < Key , ( ) > { debug_assert ! ( pairs iter ( ) zip ( pairs iter ( ) skip ( 1 ) ) all ( ( ( a ) ( b ) ) a b ) ) ; if let & Json :: Object ( ref obj ) = json { let btree : & BTreeMap < _ , _ > = obj ; // assert it's BTree // because we care about order let mut errors = 0 ; let num = btree . len ( ) + pairs . len ( ) - pairs . iter ( ) . filter ( | & & ( x , _ ) | btree . contains_key ( x ) ) . count ( ) ; let res = Key :: from_iter ( Merge ( num , pairs . iter ( ) . cloned ( ) . peekable ( ) , btree . iter ( ) . map ( | ( ref k , v ) | { match v { & Json :: String ( ref val ) => { ( & k [ .. ] , & val [ .. ] ) } // TODO(tailhook) probably support numbers _ => { errors += 1 ; ( & k [ .. ] , " " ) } } } ) . peekable ( ) , PhantomData , ) ) ; if errors > 0 { return Err ( ( ) ) ; } return Ok ( res ) ; } else { return Err ( ( ) ) ; } }
Creates a key json object with additional pairs added
Note pairs should be sorted
Creates a key json object with additional pairs added Note pairs should be sorted
json
&Json
pairs
&[(&str, &str)]
json
&Json
pairs
&[(&str, &str)]