/// find the current highlighted item in the given 'plist_val' plist
/// and place it into the settings. held_item and held_key
/// if 'first' is true get the first key of a dict or item 0 of an array
/// if 'preserve' is true do not clear the held values to their defaults
find the current highlighted item in the given 'plist_val' plist
and place it into the settings. held_item and held_key
if 'first' is true get the first key of a dict or item 0 of an array
if 'preserve' is true do not clear the held values to their defaults
find the current highlighted item in the given ' plist_val ' plist and place it into the settings . held_item and held_key if ' first ' is true get the first key of a dict or item 0 of an array if ' preserve ' is true do not clear the held values to their defaults
pub fn extract_value(
    settings: &mut Settings,
    mut plist_val: &Value,
    first: bool,
    preserve: bool,
) -> bool {
    let mut extracted = true;
    for i in 0..settings.depth {
        match plist_val {
            Value::Dictionary(d) => {
                plist_val = match d.get(&settings.sec_key[i]) {
                    Some(k) => k,
                    None => return false,
                }
            }
            Value::Array(a) => {
                plist_val = a.get(0).expect("No 0 element in Sample.plist");
            }
            _ => (),
        }
    }
    match plist_val {
        Value::Dictionary(d) => {
            let key = if first {
                d.keys().next().expect("Didn't get first key").clone()
            } else {
                settings.sec_key[settings.depth].clone()
            };
            match d.get(&key) {
                Some(v) => {
                    settings.held_item = Some(v.to_owned());
                    settings.held_key = key.to_owned();
                }
                None => extracted = false,
            };
        }
        Value::Array(a) => {
            let num = if first {
                0
            } else {
                settings.sec_num[settings.depth]
            };
            if num < a.len() {
                let mut ex_item = a.get(num).unwrap().to_owned();
                match ex_item.as_dictionary_mut() {
                    Some(d) => {
                        if !preserve {
                            for val in d.values_mut() {
                                match val {
                                    Value::String(_) => *val = Value::String("".to_string()),
                                    Value::Boolean(_) => *val = Value::Boolean(false),
                                    _ => (),
                                }
                            }
                        }
                        settings.held_item = Some(ex_item);
                        settings.held_key = settings.sec_key[settings.depth].clone();
                    }
                    None => settings.held_item = Some(ex_item), // not a dict in an array, return element "num"
                }
            } else {
                extracted = false;
            }
        }
        _ => extracted = false, // not a dict or array
    }
    extracted
}
pub fn extract_value ( settings : & mut Settings , mut plist_val : & Value , first : bool , preserve : bool , ) -> bool { let mut extracted = true ; for i in 0 .. settings . depth { match plist_val { Value :: Dictionary ( d ) => { plist_val = match d . get ( & settings . sec_key [ i ] ) { Some ( k ) => k , None => return false , } } Value :: Array ( a ) => { plist_val = a . get ( 0 ) . expect ( " " ) ; } _ => ( ) , } } match plist_val { Value :: Dictionary ( d ) => { let key = if first { d . keys ( ) . next ( ) . expect ( " " ) . clone ( ) } else { settings . sec_key [ settings . depth ] . clone ( ) } ; match d . get ( & key ) { Some ( v ) => { settings . held_item = Some ( v . to_owned ( ) ) ; settings . held_key = key . to_owned ( ) ; } None => extracted = false , } ; } Value :: Array ( a ) => { let num = if first { 0 } else { settings . sec_num [ settings . depth ] } ; if num < a . len ( ) { let mut ex_item = a . get ( num ) . unwrap ( ) . to_owned ( ) ; match ex_item . as_dictionary_mut ( ) { Some ( d ) => { if ! preserve { for val in d . values_mut ( ) { match val { Value :: String ( _ ) => * val = Value :: String ( " " . to_string ( ) ) , Value :: Boolean ( _ ) => * val = Value :: Boolean ( false ) , _ => ( ) , } } } settings . held_item = Some ( ex_item ) ; settings . held_key = settings . sec_key [ settings . depth ] . clone ( ) ; } None => settings . held_item = Some ( ex_item ) , // not a dict in an array, return element "num" } } else { extracted = false ; } } _ => extracted = false , // not a dict or array } extracted }
find the current highlighted item in the given 'plist_val' plist
and place it into the settings.
find the current highlighted item in the given ' plist_val ' plist and place it into the settings .
settings
&mut Settings
plist_val
&Value
first
bool
preserve
bool