Skip to main content

Array

Struct Array 

Source
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

Source

pub fn as_ptr(&self) -> *mut JsonArray

Return the inner pointer to the underlying C value.

Source

pub unsafe fn from_glib_ptr_borrow(ptr: &*mut JsonArray) -> &Self

Borrows the underlying C value.

Source§

impl Array

Source

pub fn new() -> Array

Creates a new array.

§Returns

the newly created array

Source

pub fn sized_new(n_elements: u32) -> Array

Creates a new array with n_elements slots already allocated.

§n_elements

number of slots to pre-allocate

§Returns

the newly created array

Source

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

Source

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

Source

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

Source

pub fn add_element(&self, node: Node)

Appends the given node inside an array.

§node

the element to add

Source

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

Source

pub fn add_null_element(&self)

Conveniently adds a null element into an array

See also: add_element(), JSON_NODE_NULL

Source

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

Source

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

Source

pub fn dup_element(&self, index_: u32) -> Node

Retrieves a copy of the element at the given position in the array.

§index_

the index of the element to retrieve

§Returns

a copy of the element at the given position

Source

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

Source

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

Source

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

Source

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

Source

pub fn element(&self, index_: u32) -> Node

Retrieves the element at the given position in the array.

§index_

the index of the element to retrieve

§Returns

the element at the given position

Source

pub fn elements(&self) -> Vec<Node>

Retrieves all the elements of an array as a list of nodes.

§Returns

the elements of the array

Source

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

Source

pub fn length(&self) -> u32

Retrieves the length of the given array

§Returns

the length of the array

Source

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

Source

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

Source

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

Source

pub fn is_immutable(&self) -> bool

Available on crate feature v1_2 only.

Check whether the given array has been marked as immutable by calling seal() on it.

§Returns

true if the array is immutable

Source

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

Source

pub fn seal(&self)

Available on crate feature v1_2 only.

Seals the given array, making it immutable to further changes.

This function will recursively seal all elements in the array too.

If the array is already immutable, this is a no-op.

Trait Implementations§

Source§

impl Clone for Array

Source§

fn clone(&self) -> Self

Makes a clone of this shared reference.

This increments the strong reference count of the reference. Dropping the reference will decrement it again.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Array

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Array

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Array

Available on crate feature v1_2 only.
Source§

impl From<Array> for Value

Source§

fn from(s: Array) -> Self

Converts to this type from the input type.
Source§

impl HasParamSpec for Array

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = Array

Preferred value to be used as setter for the associated ParamSpec.
Source§

type BuilderFn = fn(&str) -> ParamSpecBoxedBuilder<'_, Array>

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for Array

Available on crate feature v1_2 only.
Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Array

Source§

fn cmp(&self, other: &Array) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for Array

Available on crate feature v1_2 only.
Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Array

Source§

fn partial_cmp(&self, other: &Array) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for Array

Source§

fn static_type() -> Type

Returns the type identifier of Self.

Auto Trait Implementations§

§

impl !Send for Array

§

impl !Sync for Array

§

impl Freeze for Array

§

impl RefUnwindSafe for Array

§

impl Unpin for Array

§

impl UnsafeUnpin for Array

§

impl UnwindSafe for Array

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

Source§

impl<T> Property for T
where T: HasParamSpec,

Source§

type Value = T

Source§

impl<T> PropertyGet for T
where T: HasParamSpec,

Source§

type Value = T

Source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

Source§

impl<T> StaticTypeExt for T
where T: StaticType,

Source§

fn ensure_type()

Ensures that the type has been registered with the type system.
Source§

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T

Source§

impl<'a, T> ToGlibContainerFromSlice<'a, *const GPtrArray> for T

Source§

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T

Source§

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> TransparentType for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.