Skip to main content

ReaderExt

Trait ReaderExt 

Source
pub trait ReaderExt: IsA<Reader> + 'static {
Show 21 methods // Provided methods fn count_elements(&self) -> i32 { ... } fn count_members(&self) -> i32 { ... } fn end_element(&self) { ... } fn end_member(&self) { ... } fn is_boolean_value(&self) -> bool { ... } fn double_value(&self) -> f64 { ... } fn error(&self) -> Option<Error> { ... } fn int_value(&self) -> i64 { ... } fn member_name(&self) -> Option<GString> { ... } fn is_null_value(&self) -> bool { ... } fn string_value(&self) -> GString { ... } fn value(&self) -> Option<Node> { ... } fn is_array(&self) -> bool { ... } fn is_object(&self) -> bool { ... } fn is_value(&self) -> bool { ... } fn list_members(&self) -> Vec<GString> { ... } fn read_element(&self, index_: u32) -> bool { ... } fn read_member(&self, member_name: &str) -> bool { ... } fn set_root(&self, root: Option<&Node>) { ... } fn root(&self) -> Option<Node> { ... } fn connect_root_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all Reader methods.

§Implementors

Reader

Provided Methods§

Source

fn count_elements(&self) -> i32

Counts the elements of the current position, if the reader is positioned on an array.

In case of failure, the reader is set to an error state.

§Returns

the number of elements, or -1.

Source

fn count_members(&self) -> i32

Counts the members of the current position, if the reader is positioned on an object.

In case of failure, the reader is set to an error state.

§Returns

the number of members, or -1

Source

fn end_element(&self)

Moves the cursor back to the previous node after being positioned inside an array.

This function resets the error state of the reader, if any was set.

Source

fn end_member(&self)

Moves the cursor back to the previous node after being positioned inside an object.

This function resets the error state of the reader, if any was set.

Source

fn is_boolean_value(&self) -> bool

Retrieves the boolean value of the current position of the reader.

See also: value()

§Returns

the boolean value

Source

fn double_value(&self) -> f64

Retrieves the floating point value of the current position of the reader.

See also: value()

§Returns

the floating point value

Source

fn error(&self) -> Option<Error>

Retrieves the error currently set on the reader.

§Returns

the current error

Source

fn int_value(&self) -> i64

Retrieves the integer value of the current position of the reader.

See also: value()

§Returns

the integer value

Source

fn member_name(&self) -> Option<GString>

Retrieves the name of the current member.

In case of failure, the reader is set to an error state.

§Returns

the name of the member

Source

fn is_null_value(&self) -> bool

Checks whether the value of the current position of the reader is null.

See also: value()

§Returns

TRUE if null is set, and FALSE otherwise

Source

fn string_value(&self) -> GString

Retrieves the string value of the current position of the reader.

See also: value()

§Returns

the string value

Source

fn value(&self) -> Option<Node>

Retrieves the value node at the current position of the reader.

If the current position does not contain a scalar value, the reader is set to an error state.

§Returns

the current value node

Source

fn is_array(&self) -> bool

Checks whether the reader is currently on an array.

§Returns

TRUE if the reader is on an array

Source

fn is_object(&self) -> bool

Checks whether the reader is currently on an object.

§Returns

TRUE if the reader is on an object

Source

fn is_value(&self) -> bool

Checks whether the reader is currently on a value.

§Returns

TRUE if the reader is on a value

Source

fn list_members(&self) -> Vec<GString>

Retrieves a list of member names from the current position, if the reader is positioned on an object.

In case of failure, the reader is set to an error state.

§Returns

the members of the object

Source

fn read_element(&self, index_: u32) -> bool

Advances the cursor of the reader to the element of the array or the member of the object at the given position.

You can use value() and its wrapper functions to retrieve the value of the element; for instance, the following code will read the first element of the array at the current cursor position:

⚠️ The following code is in c ⚠️

json_reader_read_element (reader, 0);
int_value = json_reader_get_int_value (reader);

After reading the value, you should call end_element() to reposition the cursor inside the reader, e.g.:

⚠️ The following code is in c ⚠️

const char *str_value = NULL;

json_reader_read_element (reader, 1);
str_value = json_reader_get_string_value (reader);
json_reader_end_element (reader);

json_reader_read_element (reader, 2);
str_value = json_reader_get_string_value (reader);
json_reader_end_element (reader);

If the reader is not currently on an array or an object, or if the index is bigger than the size of the array or the object, the reader will be put in an error state until end_element() is called. This means that, if used conditionally, end_element() must be called on all branches:

⚠️ The following code is in c ⚠️

if (!json_reader_read_element (reader, 1))
  {
    g_propagate_error (error, json_reader_get_error (reader));
    json_reader_end_element (reader);
    return FALSE;
  }
else
  {
    const char *str_value = json_reader_get_string_value (reader);
    json_reader_end_element (reader);

    // use str_value

    return TRUE;
  }
```c
## `index_`
the index of the element

# Returns

`TRUE` on success, and `FALSE` otherwise
Source

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

Advances the cursor of the reader to the member_name of the object at the current position.

You can use value() and its wrapper functions to retrieve the value of the member; for instance:

⚠️ The following code is in c ⚠️

json_reader_read_member (reader, "width");
width = json_reader_get_int_value (reader);

After reading the value, json_reader_end_member() should be called to reposition the cursor inside the reader, e.g.:

⚠️ The following code is in c ⚠️

json_reader_read_member (reader, "author");
author = json_reader_get_string_value (reader);
json_reader_end_member (reader);

json_reader_read_member (reader, "title");
title = json_reader_get_string_value (reader);
json_reader_end_member (reader);

If the reader is not currently on an object, or if the member_name is not defined in the object, the reader will be put in an error state until end_member() is called. This means that if used conditionally, end_member() must be called on all branches:

⚠️ The following code is in c ⚠️

if (!json_reader_read_member (reader, "title"))
  {
    g_propagate_error (error, json_reader_get_error (reader));
    json_reader_end_member (reader);
    return FALSE;
  }
else
  {
    const char *str_value = json_reader_get_string_value (reader);
    json_reader_end_member (reader);

    // use str_value

    return TRUE;
  }
§member_name

the name of the member to read

§Returns

TRUE on success, and FALSE otherwise

Source

fn set_root(&self, root: Option<&Node>)

Sets the root node of the JSON tree to be read by @self.

The reader will take a copy of the node.

§root

the root node

Source

fn root(&self) -> Option<Node>

The root of the JSON tree that the reader should read.

Source

fn connect_root_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<O: IsA<Reader>> ReaderExt for O