pub struct Array { /* private fields */ }Expand description
JsonArray is the representation of the array type inside JSON.
A JsonArray contains Node elements, which may contain
fundamental types, other arrays or objects.
Since arrays can be arbitrarily big, copying them can be expensive; for
this reason, they are reference counted. You can control the lifetime of
a JsonArray using Json::Array::ref() and Json::Array::unref().
To append an element, use add_element().
To extract an element at a given index, use element().
To retrieve the entire array in list form, use elements().
To retrieve the length of the array, use length().
GLib type: Shared boxed type with reference counted clone semantics.
Implementations§
Source§impl Array
impl Array
Sourcepub fn add_array_element(&self, value: Option<Array>)
pub fn add_array_element(&self, value: Option<Array>)
Conveniently adds an array element into an array.
If value is NULL, a null element will be added instead.
See also: add_element(), Node::take_array()
§value
the array to add
Sourcepub fn add_boolean_element(&self, value: bool)
pub fn add_boolean_element(&self, value: bool)
Conveniently adds the given boolean value into an array.
See also: add_element(), Node::set_boolean()
§value
the boolean value to add
Sourcepub fn add_double_element(&self, value: f64)
pub fn add_double_element(&self, value: f64)
Conveniently adds the given floating point value into an array.
See also: add_element(), Node::set_double()
§value
the floating point value to add
Sourcepub fn add_element(&self, node: Node)
pub fn add_element(&self, node: Node)
Sourcepub fn add_int_element(&self, value: i64)
pub fn add_int_element(&self, value: i64)
Conveniently adds the given integer value into an array.
See also: add_element(), Node::set_int()
§value
the integer value to add
Sourcepub fn add_null_element(&self)
pub fn add_null_element(&self)
Conveniently adds a null element into an array
See also: add_element(), JSON_NODE_NULL
Sourcepub fn add_object_element(&self, value: Option<Object>)
pub fn add_object_element(&self, value: Option<Object>)
Conveniently adds an object into an array.
If value is NULL, a null element will be added instead.
See also: add_element(), Node::take_object()
§value
the object to add
Sourcepub fn add_string_element(&self, value: &str)
pub fn add_string_element(&self, value: &str)
Conveniently adds the given string value into an array.
See also: add_element(), Node::set_string()
§value
the string value to add
Sourcepub fn dup_element(&self, index_: u32) -> Node
pub fn dup_element(&self, index_: u32) -> Node
Sourcepub fn foreach_element<P: FnMut(&Array, u32, &Node)>(&self, func: P)
pub fn foreach_element<P: FnMut(&Array, u32, &Node)>(&self, func: P)
Iterates over all elements of an array, and calls a function on each one of them.
It is safe to change the value of an element of the array while iterating over it, but it is not safe to add or remove elements from the array.
§func
the function to be called on each element
Sourcepub fn array_element(&self, index_: u32) -> Array
pub fn array_element(&self, index_: u32) -> Array
Conveniently retrieves the array at the given position inside an array.
See also: element(), Node::array()
§index_
the index of the element to retrieve
§Returns
the array
Sourcepub fn is_boolean_element(&self, index_: u32) -> bool
pub fn is_boolean_element(&self, index_: u32) -> bool
Conveniently retrieves the boolean value of the element at the given position inside an array.
See also: element(), Node::is_boolean()
§index_
the index of the element to retrieve
§Returns
the boolean value
Sourcepub fn double_element(&self, index_: u32) -> f64
pub fn double_element(&self, index_: u32) -> f64
Conveniently retrieves the floating point value of the element at the given position inside an array.
See also: element(), Node::double()
§index_
the index of the element to retrieve
§Returns
the floating point value
Sourcepub fn int_element(&self, index_: u32) -> i64
pub fn int_element(&self, index_: u32) -> i64
Conveniently retrieves the integer value of the element at the given position inside an array.
See also: element(), Node::int()
§index_
the index of the element to retrieve
§Returns
the integer value
Sourcepub fn is_null_element(&self, index_: u32) -> bool
pub fn is_null_element(&self, index_: u32) -> bool
Conveniently checks whether the element at the given position inside the
array contains a null value.
See also: element(), Node::is_null()
§index_
the index of the element to retrieve
§Returns
TRUE if the element is null
Sourcepub fn object_element(&self, index_: u32) -> Object
pub fn object_element(&self, index_: u32) -> Object
Conveniently retrieves the object at the given position inside an array.
See also: element(), Node::object()
§index_
the index of the element to retrieve
§Returns
the object
Sourcepub fn string_element(&self, index_: u32) -> GString
pub fn string_element(&self, index_: u32) -> GString
Conveniently retrieves the string value of the element at the given position inside an array.
See also: element(), Node::string()
§index_
the index of the element to retrieve
§Returns
the string value
Sourcepub fn is_immutable(&self) -> bool
Available on crate feature v1_2 only.
pub fn is_immutable(&self) -> bool
v1_2 only.Sourcepub fn remove_element(&self, index_: u32)
pub fn remove_element(&self, index_: u32)
Removes the element at the given position inside an array.
This function will release the reference held on the element.
§index_
the position of the element to be removed
Trait Implementations§
impl Eq for Array
v1_2 only.Source§impl HasParamSpec for Array
impl HasParamSpec for Array
Source§impl Ord for Array
impl Ord for Array
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Array
impl PartialOrd for Array
Source§impl StaticType for Array
impl StaticType for Array
Source§fn static_type() -> Type
fn static_type() -> Type
Self.