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 { ... }
}Provided Methods§
Sourcefn count_elements(&self) -> i32
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.
Sourcefn count_members(&self) -> i32
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
Sourcefn end_element(&self)
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.
Sourcefn end_member(&self)
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.
Sourcefn is_boolean_value(&self) -> bool
fn is_boolean_value(&self) -> bool
Sourcefn double_value(&self) -> f64
fn double_value(&self) -> f64
Sourcefn member_name(&self) -> Option<GString>
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
Sourcefn is_null_value(&self) -> bool
fn is_null_value(&self) -> bool
Sourcefn string_value(&self) -> GString
fn string_value(&self) -> GString
Sourcefn value(&self) -> Option<Node>
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
Sourcefn list_members(&self) -> Vec<GString>
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
Sourcefn read_element(&self, index_: u32) -> bool
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` otherwiseSourcefn read_member(&self, member_name: &str) -> bool
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
Sourcefn set_root(&self, root: Option<&Node>)
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
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".