(
token: Token<'_>,
remaining: &Pointer,
array: &'v mut Vec<Value>,
src: Value,
position: usize,
offset: usize,
)
| 329 | } |
| 330 | #[allow(clippy::needless_pass_by_value)] |
| 331 | fn assign_array<'v>( |
| 332 | token: Token<'_>, |
| 333 | remaining: &Pointer, |
| 334 | array: &'v mut Vec<Value>, |
| 335 | src: Value, |
| 336 | position: usize, |
| 337 | offset: usize, |
| 338 | ) -> Result<Assigned<'v, Value>, Error> { |
| 339 | // parsing the index |
| 340 | let idx = token |
| 341 | .to_index() |
| 342 | .map_err(|source| Error::FailedToParseIndex { |
| 343 | position, |
| 344 | offset, |
| 345 | source, |
| 346 | })? |
| 347 | .for_len_incl(array.len()) |
| 348 | .map_err(|source| Error::OutOfBounds { |
| 349 | position, |
| 350 | offset, |
| 351 | source, |
| 352 | })?; |
| 353 | |
| 354 | debug_assert!(idx <= array.len()); |
| 355 | |
| 356 | if idx < array.len() { |
| 357 | // element exists in the array, we either need to replace it or continue |
| 358 | // depending on whether this is the last token or not |
| 359 | if remaining.is_root() { |
| 360 | // last token, we replace the value and call it a day |
| 361 | Ok(Assigned::Done(Some(mem::replace(&mut array[idx], src)))) |
| 362 | } else { |
| 363 | // not the last token, we continue with a mut ref to the element as |
| 364 | // the next value |
| 365 | Ok(Assigned::Continue { |
| 366 | next_dest: &mut array[idx], |
| 367 | same_value: src, |
| 368 | }) |
| 369 | } |
| 370 | } else { |
| 371 | // element does not exist in the array. |
| 372 | // we create the path and assign the value |
| 373 | let src = expand(remaining, src); |
| 374 | array.push(src); |
| 375 | Ok(Assigned::Done(None)) |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | #[allow(clippy::needless_pass_by_value)] |
| 380 | fn assign_object<'v>( |
no test coverage detected