Skip to main content

Object

Struct Object 

Source
pub struct Object { /* private fields */ }
Expand description

JsonObject is the representation of the object type inside JSON.

A JsonObject contains Node “members”, which may contain fundamental types, arrays or other objects; each member of an object is accessed using a unique string, or “name”.

Since objects can be arbitrarily big, copying them can be expensive; for this reason they are reference counted. You can control the lifetime of a JsonObject using Json::Object::ref() and Json::Object::unref().

To add or overwrite a member with a given name, use set_member().

To extract a member with a given name, use member().

To retrieve the list of members, use members().

To retrieve the size of the object (that is, the number of members it has), use size().

GLib type: Shared boxed type with reference counted clone semantics.

Implementations§

Source§

impl Object

Source

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

Return the inner pointer to the underlying C value.

Source

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

Borrows the underlying C value.

Source§

impl Object

Source

pub fn new() -> Object

Creates a new object.

§Returns

the newly created object

Source

pub fn dup_member(&self, member_name: &str) -> Option<Node>

Retrieves a copy of the value of the given member inside an object.

§member_name

the name of the JSON object member to access

§Returns

a copy of the value for the requested object member

Source

pub fn foreach_member<P: FnMut(&Object, &str, &Node)>(&self, func: P)

Iterates over all members of @self and calls @func on each one of them.

It is safe to change the value of a member of the oobject from within the iterator function, but it is not safe to add or remove members from the object.

The order in which the object members are iterated is the insertion order.

§func

the function to be called on each member

Source

pub fn array_member(&self, member_name: &str) -> Option<Array>

Convenience function that retrieves the array stored in @member_name of @self. It is an error to specify a @member_name which does not exist or which holds a non-null, non-array value.

If @member_name contains null, then this function will return NULL.

See also: member(), has_member()

§member_name

the name of the member

§Returns

the array inside the object’s member

Source

pub fn is_boolean_member(&self, member_name: &str) -> bool

Convenience function that retrieves the boolean value stored in @member_name of @self. It is an error to specify a @member_name which does not exist or which holds a non-scalar, non-null value.

See also: [is_boolean_member_with_default()][Self::is_boolean_member_with_default()], member(), has_member()

§member_name

the name of the member

§Returns

the boolean value of the object’s member

Source

pub fn double_member(&self, member_name: &str) -> f64

Convenience function that retrieves the floating point value stored in @member_name of @self. It is an error to specify a @member_name which does not exist or which holds a non-scalar, non-null value.

See also: [double_member_with_default()][Self::double_member_with_default()], member(), has_member()

§member_name

the name of the member

§Returns

the floating point value of the object’s member

Source

pub fn int_member(&self, member_name: &str) -> i64

Convenience function that retrieves the integer value stored in @member_name of @self. It is an error to specify a @member_name which does not exist or which holds a non-scalar, non-null value.

See also: [int_member_with_default()][Self::int_member_with_default()], member(), has_member()

§member_name

the name of the object member

§Returns

the integer value of the object’s member

Source

pub fn member(&self, member_name: &str) -> Option<Node>

Retrieves the value of the given member inside an object.

§member_name

the name of the JSON object member to access

§Returns

the value for the requested object member

Source

pub fn members(&self) -> Vec<GString>

Retrieves all the names of the members of an object.

You can obtain the value for each member by iterating the returned list and calling member().

§Returns

the member names of the object

Source

pub fn is_null_member(&self, member_name: &str) -> bool

Convenience function that checks whether the value stored in @member_name of @self is null. It is an error to specify a @member_name which does not exist.

See also: member(), has_member()

§member_name

the name of the member

§Returns

TRUE if the value is null

Source

pub fn object_member(&self, member_name: &str) -> Option<Object>

Convenience function that retrieves the object stored in @member_name of @self. It is an error to specify a @member_name which does not exist or which holds a non-null, non-object value.

If @member_name contains null, then this function will return NULL.

See also: member(), has_member()

§member_name

the name of the member

§Returns

the object inside the object’s member

Source

pub fn size(&self) -> u32

Retrieves the number of members of a JSON object.

§Returns

the number of members

Source

pub fn string_member(&self, member_name: &str) -> GString

Convenience function that retrieves the string value stored in @member_name of @self. It is an error to specify a @member_name that does not exist or which holds a non-scalar, non-null value.

See also: [string_member_with_default()][Self::string_member_with_default()], member(), has_member()

§member_name

the name of the member

§Returns

the string value of the object’s member

Source

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

Retrieves all the values of the members of an object.

§Returns

the member values of the object

Source

pub fn has_member(&self, member_name: &str) -> bool

Checks whether @self has a member named @member_name.

§member_name

the name of a JSON object member

§Returns

TRUE if the JSON object has the requested member

Source

pub fn is_immutable(&self) -> bool

Available on crate feature v1_2 only.

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

§Returns

TRUE if the object is immutable

Source

pub fn remove_member(&self, member_name: &str)

Removes @member_name from @self, freeing its allocated resources.

§member_name

the name of the member to remove

Source

pub fn seal(&self)

Available on crate feature v1_2 only.

Seals the object, making it immutable to further changes.

This function will recursively seal all members of the object too.

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

Source

pub fn set_array_member(&self, member_name: &str, value: Array)

Convenience function for setting an object member with an array value.

See also: set_member(), Node::take_array()

§member_name

the name of the member

§value

the value of the member

Source

pub fn set_boolean_member(&self, member_name: &str, value: bool)

Convenience function for setting an object member with a boolean value.

See also: set_member(), Node::init_boolean()

§member_name

the name of the member

§value

the value of the member

Source

pub fn set_double_member(&self, member_name: &str, value: f64)

Convenience function for setting an object member with a floating point value.

See also: set_member(), Node::init_double()

§member_name

the name of the member

§value

the value of the member

Source

pub fn set_int_member(&self, member_name: &str, value: i64)

Convenience function for setting an object member with an integer value.

See also: set_member(), Node::init_int()

§member_name

the name of the member

§value

the value of the member

Source

pub fn set_member(&self, member_name: &str, node: Node)

Sets the value of a member inside an object.

If the object does not have a member with the given name, a new member is created.

If the object already has a member with the given name, the current value is overwritten with the new.

§member_name

the name of the member

§node

the value of the member

Source

pub fn set_null_member(&self, member_name: &str)

Convenience function for setting an object member with a null value.

See also: set_member(), Node::init_null()

§member_name

the name of the member

Source

pub fn set_object_member(&self, member_name: &str, value: Object)

Convenience function for setting an object member with an object value.

See also: set_member(), Node::take_object()

§member_name

the name of the member

§value

the value of the member

Source

pub fn set_string_member(&self, member_name: &str, value: &str)

Convenience function for setting an object member with a string value.

See also: set_member(), Node::init_string()

§member_name

the name of the member

§value

the value of the member

Trait Implementations§

Source§

impl Clone for Object

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 Object

Source§

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

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

impl Default for Object

Source§

fn default() -> Self

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

impl Eq for Object

Available on crate feature v1_2 only.
Source§

impl From<Object> for Value

Source§

fn from(s: Object) -> Self

Converts to this type from the input type.
Source§

impl HasParamSpec for Object

Source§

type ParamSpec = ParamSpecBoxed

Source§

type SetValue = Object

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

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

Source§

fn param_spec_builder() -> Self::BuilderFn

Source§

impl Hash for Object

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 Object

Source§

fn cmp(&self, other: &Object) -> 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 Object

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 Object

Source§

fn partial_cmp(&self, other: &Object) -> 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 Object

Source§

fn static_type() -> Type

Returns the type identifier of Self.

Auto Trait Implementations§

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.