| 454 | } |
| 455 | |
| 456 | fn pointer_mut<'a>(v: &'a mut JValue, tokens: &[String]) -> &'a mut JValue { |
| 457 | if tokens.is_empty() { |
| 458 | v |
| 459 | } else { |
| 460 | let mut target = v; |
| 461 | |
| 462 | for token in tokens { |
| 463 | // borrow checker gets confused about `target` being |
| 464 | // mutably borrowed too many times because of the loop |
| 465 | // this once-per-loop binding makes the scope clearer and |
| 466 | // circumvents the error |
| 467 | let target_once = target; |
| 468 | |
| 469 | target = match *target_once { |
| 470 | JValue::Object(ref mut map) => { |
| 471 | if !map.contains_key(token) { |
| 472 | map.insert(token.to_string(), JValue::Object(Map::new())); |
| 473 | } |
| 474 | |
| 475 | map.get_mut(token).unwrap() |
| 476 | } |
| 477 | // JValue::Array(ref mut list) => { |
| 478 | // parse_index(&token).and_then(move |x| list.get_mut(x)) |
| 479 | // } |
| 480 | _ => panic!("failed to acquire pointer to {:?}", tokens), |
| 481 | }; |
| 482 | } |
| 483 | |
| 484 | target |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | // fn parse_index(s: &str) -> Option<usize> { |
| 489 | // if s.starts_with('+') || (s.starts_with('0') && s.len() != 1) { |