Skip to content

Commit

Permalink
Merge pull request #11 from mu2019/patch-2
Browse files Browse the repository at this point in the history
Update mod.rs.add array_insert method.
  • Loading branch information
gierens authored Oct 25, 2023
2 parents e5fae4a + f0c9745 commit 739d16c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,20 @@ impl JsonValue {
}
}

/// Works on `JsonValue::Array` - insert an entry at given index.
/// If the method is called on anything but an aray or if the index is out
/// of bounds, it will return an error.
pub fn array_insert<T>(&mut self, index: usize, value: T) -> Result<()>
where T: Into<JsonValue> {
match *self {
JsonValue::Array(ref mut vec) => {
vec.insert(index, value.into());
Ok(())
},
_ => Err(Error::wrong_type("Array"))
}
}

/// When called on an array or an object, will wipe them clean. When called
/// on a string will clear the string. Numbers and booleans become null.
pub fn clear(&mut self) {
Expand Down

0 comments on commit 739d16c

Please sign in to comment.