pub struct Array { /* private fields */ }Expand description
Represents a JSON array.
Implementations§
Source§impl Array
impl Array
Sourcepub fn add(&self, value: &Value) -> Self
pub fn add(&self, value: &Value) -> Self
Adds a JSON value to an array.
assert_eq!(Some(true), Array::new().add(&Value::Bool(true)).get_bool(0).ok().flatten());Sourcepub fn add_array(&self, value: &Array) -> Self
pub fn add_array(&self, value: &Array) -> Self
Adds an array to an array.
assert_eq!(
Some(0),
Array::new()
.add_array(&Array::new().add_integer(0))
.get_array(0).ok().flatten().and_then(|a| a.get_integer(0).ok().flatten()));pub fn add_array_p(&self, pointer: &str, value: &Array) -> Option<Self>
Sourcepub fn add_bool(&self, value: bool) -> Self
pub fn add_bool(&self, value: bool) -> Self
Adds a bool to an array.
assert_eq!(Some(true), Array::new().add_bool(true).get_bool(0).ok().flatten());pub fn add_bool_p(&self, pointer: &str, value: bool) -> Option<Self>
Sourcepub fn add_decimal(&self, value: f64) -> Self
pub fn add_decimal(&self, value: f64) -> Self
Adds a decimal to an array.
assert_eq!(Some(2.0), Array::new().add_decimal(2.0).get_decimal(0).ok().flatten());pub fn add_decimal_p(&self, pointer: &str, value: f64) -> Option<Self>
Sourcepub fn add_integer(&self, value: i128) -> Self
pub fn add_integer(&self, value: i128) -> Self
Adds an integer to an array.
assert_eq!(Some(0), Array::new().add_integer(0).get_integer(0).ok().flatten());pub fn add_integer_p(&self, pointer: &str, value: i128) -> Option<Self>
Sourcepub fn add_number(&self, value: Number) -> Self
pub fn add_number(&self, value: Number) -> Self
Adds a number to an array.
assert_eq!(
Some(Integer(0)),
Array::new().add_number(Integer(0)).get_number(0).ok().flatten());pub fn add_number_p(&self, pointer: &str, value: Number) -> Option<Self>
Sourcepub fn add_object(&self, value: &Object) -> Self
pub fn add_object(&self, value: &Object) -> Self
Adds an object to an array.
assert_eq!(
Some(0),
Array::new()
.add_object(&Object::new().add_integer("test", 0))
.get_object(0).ok().flatten().and_then(|o| o.get_integer("test")));pub fn add_object_p(&self, pointer: &str, value: &Object) -> Option<Self>
pub fn add_p(&self, pointer: &str, value: &Value) -> Option<Self>
Sourcepub fn add_string(&self, value: &str) -> Self
pub fn add_string(&self, value: &str) -> Self
Adds a string to an array.
assert_eq!(
Some("test".to_string()),
Array::new().add_string("test").get_string(0).ok().flatten());pub fn add_string_p(&self, pointer: &str, value: &str) -> Option<Self>
Sourcepub fn append(&self, array: &Array) -> Self
pub fn append(&self, array: &Array) -> Self
Appends an array to the current array.
assert_eq!(
Array::new().add_integer(0).add_integer(1),
Array::new().add_integer(0).append(&Array::new().add_integer(1)))Sourcepub fn get(&self, index: usize) -> Result<Value, JsonIndexError>
pub fn get(&self, index: usize) -> Result<Value, JsonIndexError>
Gets a JSON value from an array at a given index, which is positive and less than the length of the array.
Sourcepub fn get_array(&self, index: usize) -> Result<Option<Array>, JsonIndexError>
pub fn get_array(&self, index: usize) -> Result<Option<Array>, JsonIndexError>
Gets an array from an array at a given index, which is positive and less than the length
of the array. If the value at the position is not an array, None is returned.
let array = Array::new().add_number(Integer(0));
assert_eq!(Some(Integer(0)), array.get_number(0).ok().flatten());
assert_eq!(None, array.get_string(0).ok().flatten());
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.get_number(1).err());pub fn get_array_p(&self, pointer: &str) -> Option<Array>
Sourcepub fn get_bool(&self, index: usize) -> Result<Option<bool>, JsonIndexError>
pub fn get_bool(&self, index: usize) -> Result<Option<bool>, JsonIndexError>
Gets a bool from an array at a given index, which is positive and less than the length
of the array. If the value at the position is not a Boolean, None is returned.
let array = Array::new().add_bool(true);
assert_eq!(Some(true), array.get_bool(0).ok().flatten());
assert_eq!(None, array.get_string(0).ok().flatten());
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.get_bool(1).err());pub fn get_bool_p(&self, pointer: &str) -> Option<bool>
Sourcepub fn get_decimal(&self, index: usize) -> Result<Option<f64>, JsonIndexError>
pub fn get_decimal(&self, index: usize) -> Result<Option<f64>, JsonIndexError>
Gets a decimal from an array at a given index, which is positive and less than the length
of the array. If the value at the position is not a decimal, None is returned.
let array = Array::new().add_decimal(2.0);
assert_eq!(Some(2.0), array.get_decimal(0).ok().flatten());
assert_eq!(None, array.get_string(0).ok().flatten());
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.get_decimal(1).err());pub fn get_decimal_p(&self, pointer: &str) -> Option<f64>
Sourcepub fn get_integer(&self, index: usize) -> Result<Option<i128>, JsonIndexError>
pub fn get_integer(&self, index: usize) -> Result<Option<i128>, JsonIndexError>
Gets an integer from an array at a given index, which is positive and less than the length
of the array. If the value at the position is not an integer, None is returned.
let array = Array::new().add_integer(0);
assert_eq!(Some(0), array.get_integer(0).ok().flatten());
assert_eq!(None, array.get_string(0).ok().flatten());
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.get_integer(1).err());pub fn get_integer_p(&self, pointer: &str) -> Option<i128>
Sourcepub fn get_number(&self, index: usize) -> Result<Option<Number>, JsonIndexError>
pub fn get_number(&self, index: usize) -> Result<Option<Number>, JsonIndexError>
Gets a number from an array at a given index, which is positive and less than the length
of the array. If the value at the position is not a number, None is returned.
let array = Array::new().add_number(Integer(0));
assert_eq!(Some(Integer(0)), array.get_number(0).ok().flatten());
assert_eq!(None, array.get_string(0).ok().flatten());
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.get_number(1).err());pub fn get_number_p(&self, pointer: &str) -> Option<Number>
Sourcepub fn get_object(&self, index: usize) -> Result<Option<Object>, JsonIndexError>
pub fn get_object(&self, index: usize) -> Result<Option<Object>, JsonIndexError>
Gets an object from an array at a given index, which is positive and less than the length
of the array. If the value at the position is not a JSON object, None is returned.
let array = Array::new().add_object(&Object::new().add_integer("test", 0));
assert_eq!(Some(0),
array.get_object(0).ok().flatten().and_then(|o| o.get_integer("test")));
assert_eq!(None, array.get_string(0).ok().flatten());
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.get_object(1).err());pub fn get_object_p(&self, pointer: &str) -> Option<Object>
pub fn get_p(&self, pointer: &str) -> Option<Value>
Sourcepub fn get_string(&self, index: usize) -> Result<Option<String>, JsonIndexError>
pub fn get_string(&self, index: usize) -> Result<Option<String>, JsonIndexError>
Gets a string from an array at a given index, which is positive and less than the length
of the array. If the value at the position is not a string, None is returned.
let array = Array::new().add_string("test");
assert_eq!(Some("test".to_string()), array.get_string(0).ok().flatten());
assert_eq!(None, array.get_integer(0).ok().flatten());
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.get_string(1).err());pub fn get_string_p(&self, pointer: &str) -> Option<String>
Sourcepub fn insert(
&self,
index: usize,
value: &Value,
) -> Result<Self, JsonIndexError>
pub fn insert( &self, index: usize, value: &Value, ) -> Result<Self, JsonIndexError>
Inserts a JSON value to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(Some(true), Array::new().insert(0, &Value::Bool(true))?.get_bool(0).ok().flatten());Sourcepub fn insert_array(
&self,
index: usize,
value: &Array,
) -> Result<Self, JsonIndexError>
pub fn insert_array( &self, index: usize, value: &Array, ) -> Result<Self, JsonIndexError>
Inserts an array to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(
Some(0),
Array::new()
.insert_array(0, &Array::new().insert_integer(0, 0)?)?
.get_array(0).ok().flatten().and_then(|a| a.get_integer(0).ok().flatten()));Sourcepub fn insert_bool(
&self,
index: usize,
value: bool,
) -> Result<Self, JsonIndexError>
pub fn insert_bool( &self, index: usize, value: bool, ) -> Result<Self, JsonIndexError>
Inserts a bool to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(Some(true), Array::new().insert_bool(0, true)?.get_bool(0).ok().flatten());Sourcepub fn insert_decimal(
&self,
index: usize,
value: f64,
) -> Result<Self, JsonIndexError>
pub fn insert_decimal( &self, index: usize, value: f64, ) -> Result<Self, JsonIndexError>
Inserts a decimal to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(Some(2.0), Array::new().insert_decimal(0, 2.0)?.get_decimal(0).ok().flatten());Sourcepub fn insert_integer(
&self,
index: usize,
value: i128,
) -> Result<Self, JsonIndexError>
pub fn insert_integer( &self, index: usize, value: i128, ) -> Result<Self, JsonIndexError>
Inserts an integer to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(Some(0), Array::new().insert_integer(0, 0)?.get_integer(0).ok().flatten());Sourcepub fn insert_number(
&self,
index: usize,
value: Number,
) -> Result<Self, JsonIndexError>
pub fn insert_number( &self, index: usize, value: Number, ) -> Result<Self, JsonIndexError>
Inserts a number to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(
Some(Integer(0)),
Array::new().insert_number(0, Integer(0))?.get_number(0).ok().flatten());Sourcepub fn insert_object(
&self,
index: usize,
value: &Object,
) -> Result<Self, JsonIndexError>
pub fn insert_object( &self, index: usize, value: &Object, ) -> Result<Self, JsonIndexError>
Inserts an object to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(
Some(0),
Array::new()
.insert_object(0, &Object::new().add_integer("test", 0))?
.get_object(0).ok().flatten().and_then(|o| o.get_integer("test")));Sourcepub fn insert_string(
&self,
index: usize,
value: &str,
) -> Result<Self, JsonIndexError>
pub fn insert_string( &self, index: usize, value: &str, ) -> Result<Self, JsonIndexError>
Inserts a string to an array at a given index. If the index is equal to the length of the array, the value is added at the end of it.
assert_eq!(
Some("test".to_string()),
Array::new().insert_string(0, "test")?.get_string(0).ok().flatten());Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Indicates if the array is empty or not.
assert_eq!(true, Array::new().is_empty());
assert_eq!(false, Array::new().add_integer(0).is_empty());Sourcepub fn iter(&self) -> ArrayIter<'_> ⓘ
pub fn iter(&self) -> ArrayIter<'_> ⓘ
Returns an iterator over the values of the array.
let array = Array::new().add_string("test").add_integer(1);
assert_eq!(array, Array::from_iter(array.iter()));Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of an array.
assert_eq!(0, Array::new().len());
assert_eq!(1, Array::new().add_integer(0).len());Sourcepub fn remove(&self, index: usize) -> Result<Self, JsonIndexError>
pub fn remove(&self, index: usize) -> Result<Self, JsonIndexError>
Removes a JSON value from an array at a given index, which is positive and less than the length of the array.
assert_eq!(Some(0), Array::new().add_integer(0).remove(0).ok().map(|a| a.len()));
assert_eq!(Some(JsonIndexError { index: 1, len: 0, }), Array::new().remove(1).err());pub fn remove_p(&self, pointer: &str) -> Option<Self>
Sourcepub fn set(&self, index: usize, value: &Value) -> Result<Self, JsonIndexError>
pub fn set(&self, index: usize, value: &Value) -> Result<Self, JsonIndexError>
Sets a JSON value in an array at a given index, which is positive and less than the length of the array.
Sourcepub fn set_array(
&self,
index: usize,
value: &Array,
) -> Result<Self, JsonIndexError>
pub fn set_array( &self, index: usize, value: &Array, ) -> Result<Self, JsonIndexError>
Sets an array in an array at a given index, which is positive and less than the length of the array.
let array = Array::new().add_bool(true);
assert_eq!(
Some(0),
array
.set_array(0, &Array::new().add_integer(0))
.ok()
.and_then(|a| {
a.get_array(0).ok().flatten().and_then(|a| a.get_integer(0).ok().flatten())
}));
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.set_bool(1, false).err());pub fn set_array_p(&self, pointer: &str, value: &Array) -> Option<Self>
Sourcepub fn set_bool(
&self,
index: usize,
value: bool,
) -> Result<Self, JsonIndexError>
pub fn set_bool( &self, index: usize, value: bool, ) -> Result<Self, JsonIndexError>
Sets a bool in an array at a given index, which is positive and less than the length of the array.
let array = Array::new().add_bool(true);
assert_eq!(
Some(false),
array
.set_bool(0, false)
.ok()
.and_then(|a| a.get_bool(0).ok().flatten()));
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.set_bool(1, false).err());pub fn set_bool_p(&self, pointer: &str, value: bool) -> Option<Self>
Sourcepub fn set_decimal(
&self,
index: usize,
value: f64,
) -> Result<Self, JsonIndexError>
pub fn set_decimal( &self, index: usize, value: f64, ) -> Result<Self, JsonIndexError>
Sets a decimal in an array at a given index, which is positive and less than the length of the array.
let array = Array::new().add_bool(true);
assert_eq!(
Some(3.0),
array
.set_decimal(0, 3.0)
.ok()
.and_then(|a| a.get_decimal(0).ok().flatten()));
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.set_decimal(1, 1.0).err());pub fn set_decimal_p(&self, pointer: &str, value: f64) -> Option<Self>
Sourcepub fn set_integer(
&self,
index: usize,
value: i128,
) -> Result<Self, JsonIndexError>
pub fn set_integer( &self, index: usize, value: i128, ) -> Result<Self, JsonIndexError>
Sets an integer in an array at a given index, which is positive and less than the length of the array.
let array = Array::new().add_bool(true);
assert_eq!(
Some(3),
array
.set_integer(0, 3)
.ok()
.and_then(|a| a.get_integer(0).ok().flatten()));
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.set_integer(1, 1).err());pub fn set_integer_p(&self, pointer: &str, value: i128) -> Option<Self>
Sourcepub fn set_number(
&self,
index: usize,
value: Number,
) -> Result<Self, JsonIndexError>
pub fn set_number( &self, index: usize, value: Number, ) -> Result<Self, JsonIndexError>
Sets a number in an array at a given index, which is positive and less than the length of the array.
let array = Array::new().add_bool(true);
assert_eq!(
Some(Decimal(3.0)),
array
.set_number(0, Decimal(3.0))
.ok()
.and_then(|a| a.get_number(0).ok().flatten()));
assert_eq!(
Some(JsonIndexError { index: 1, len: 1, }),
array.set_number(1, Decimal(1.0)).err());pub fn set_number_p(&self, pointer: &str, value: Number) -> Option<Self>
Sourcepub fn set_object(
&self,
index: usize,
value: &Object,
) -> Result<Self, JsonIndexError>
pub fn set_object( &self, index: usize, value: &Object, ) -> Result<Self, JsonIndexError>
Sets an object in an array at a given index, which is positive and less than the length of the array.
let array = Array::new().add_bool(true);
assert_eq!(
Some("test".to_string()),
array
.set_object(0, &Object::new().add_string("test", "test"))
.ok()
.and_then(|a| a.get_object(0).ok().flatten().and_then(|o| o.get_string("test"))));
assert_eq!(
Some(JsonIndexError { index: 1, len: 1, }),
array.set_object(1, &Object::new()).err());pub fn set_object_p(&self, pointer: &str, value: &Object) -> Option<Self>
pub fn set_p(&self, pointer: &str, value: &Value) -> Option<Self>
Sourcepub fn set_string(
&self,
index: usize,
value: &str,
) -> Result<Self, JsonIndexError>
pub fn set_string( &self, index: usize, value: &str, ) -> Result<Self, JsonIndexError>
Sets a string in an array at a given index, which is positive and less than the length of the array.
let array = Array::new().add_bool(true);
assert_eq!(
Some("test".to_string()),
array
.set_string(0, "test")
.ok()
.and_then(|a| a.get_string(0).ok().flatten()));
assert_eq!(Some(JsonIndexError { index: 1, len: 1, }), array.set_string(1, "test").err());pub fn set_string_p(&self, pointer: &str, value: &str) -> Option<Self>
Trait Implementations§
impl Eq for Array
Source§impl FromIterator<Value> for Array
impl FromIterator<Value> for Array
Source§fn from_iter<T: IntoIterator<Item = Value>>(iter: T) -> Self
fn from_iter<T: IntoIterator<Item = Value>>(iter: T) -> Self
Creates a JSON array from a stream of JSON values.
Source§impl<'a> IntoIterator for &'a Array
impl<'a> IntoIterator for &'a Array
impl StructuralPartialEq for Array
Auto Trait Implementations§
impl Freeze for Array
impl RefUnwindSafe for Array
impl Send for Array
impl Sync for Array
impl Unpin for Array
impl UnsafeUnpin for Array
impl UnwindSafe for Array
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.