Skip to content

Update mod.rs #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,19 @@ impl JsonValue {
}
}

/// Works on `JsonValue::Array` - insert an entry at index.
/// will return error not on `JsonValue::Array`.
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("I'snt an Arry"))
}
}

/// 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