Skip to main content

ParserExt

Trait ParserExt 

Source
pub trait ParserExt: IsA<Parser> + 'static {
Show 18 methods // Provided methods fn current_line(&self) -> u32 { ... } fn current_pos(&self) -> u32 { ... } fn root(&self) -> Option<Node> { ... } fn has_assignment(&self) -> Option<GString> { ... } fn load_from_data(&self, data: &str) -> Result<(), Error> { ... } fn load_from_file(&self, filename: impl AsRef<Path>) -> Result<(), Error> { ... } fn load_from_stream( &self, stream: &impl IsA<InputStream>, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error> { ... } fn load_from_stream_async<P: FnOnce(Result<(), Error>) + 'static>( &self, stream: &impl IsA<InputStream>, cancellable: Option<&impl IsA<Cancellable>>, callback: P, ) { ... } fn load_from_stream_future( &self, stream: &(impl IsA<InputStream> + Clone + 'static), ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>> { ... } fn is_immutable(&self) -> bool { ... } fn connect_array_element<F: Fn(&Self, &Array, i32) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_array_end<F: Fn(&Self, &Array) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_array_start<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_object_end<F: Fn(&Self, &Object) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_object_member<F: Fn(&Self, &Object, &str) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_object_start<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... } fn connect_parse_end<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { ... } fn connect_parse_start<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { ... }
}
Expand description

Trait containing all Parser methods.

§Implementors

Parser

Provided Methods§

Source

fn current_line(&self) -> u32

Retrieves the line currently parsed, starting from 1.

This function has defined behaviour only while parsing; calling this function from outside the signal handlers emitted by the parser will yield 0.

§Returns

the currently parsed line, or 0.

Source

fn current_pos(&self) -> u32

Retrieves the current position inside the current line, starting from 0.

This function has defined behaviour only while parsing; calling this function from outside the signal handlers emitted by the parser will yield 0.

§Returns

the position in the current line, or 0.

Source

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

Retrieves the top level node from the parsed JSON stream.

If the parser input was an empty string, or if parsing failed, the root will be NULL. It will also be NULL if it has been stolen using [steal_root()][Self::steal_root()].

§Returns

the root node.

Source

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

A JSON data stream might sometimes contain an assignment, like:

var _json_data = { "member_name" : [ ...

even though it would technically constitute a violation of the RFC.

JsonParser will ignore the left hand identifier and parse the right hand value of the assignment. JsonParser will record, though, the existence of the assignment in the data stream and the variable name used.

§Returns

TRUE if there was an assignment, and FALSE otherwise

§variable_name

the variable name

Source

fn load_from_data(&self, data: &str) -> Result<(), Error>

Loads a JSON stream from a buffer and parses it.

You can call this function multiple times with the same parser, but the contents of the parser will be destroyed each time.

§data

the buffer to parse

§length

the length of the buffer, or -1 if it is NUL terminated

§Returns

TRUE if the buffer was succesfully parsed

Source

fn load_from_file(&self, filename: impl AsRef<Path>) -> Result<(), Error>

Loads a JSON stream from the content of filename and parses it.

If the file is large or shared between processes, [load_from_mapped_file()][Self::load_from_mapped_file()] may be a more efficient way to load it.

See also: load_from_data()

§filename

the path for the file to parse

§Returns

TRUE if the file was successfully loaded and parsed.

Source

fn load_from_stream( &self, stream: &impl IsA<InputStream>, cancellable: Option<&impl IsA<Cancellable>>, ) -> Result<(), Error>

Loads the contents of an input stream and parses them.

If cancellable is not NULL, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, G_IO_ERROR_CANCELLED will be set on the given error.

§stream

the input stream with the JSON data

§cancellable

a #GCancellable

§Returns

TRUE if the data stream was successfully read and parsed, and FALSE otherwise

Source

fn load_from_stream_async<P: FnOnce(Result<(), Error>) + 'static>( &self, stream: &impl IsA<InputStream>, cancellable: Option<&impl IsA<Cancellable>>, callback: P, )

Asynchronously reads the contents of a stream.

For more details, see load_from_stream(), which is the synchronous version of this call.

When the operation is finished, @callback will be called. You should then call Json::Parser::load_from_stream_finish() to get the result of the operation.

§stream

the input stream with the JSON data

§cancellable

a #GCancellable

§callback

the function to call when the request is satisfied

Source

fn load_from_stream_future( &self, stream: &(impl IsA<InputStream> + Clone + 'static), ) -> Pin<Box_<dyn Future<Output = Result<(), Error>> + 'static>>

Source

fn is_immutable(&self) -> bool

Available on crate feature v1_2 only.

Whether the tree built by the parser should be immutable when created.

Making the output immutable on creation avoids the expense of traversing it to make it immutable later.

Source

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

The ::array-element signal is emitted each time a parser has successfully parsed a single element of a JSON array.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::array_element()][crate::subclass::prelude::ParserImpl::array_element()] virtual function

§array

a JSON array

§index_

the index of the newly parsed array element

Source

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

The ::array-end signal is emitted each time a parser has successfully parsed an entire JSON array.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::array_end()][crate::subclass::prelude::ParserImpl::array_end()] virtual function

§array

the parsed JSON array

Source

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

The ::array-start signal is emitted each time a parser starts parsing a JSON array.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::array_start()][crate::subclass::prelude::ParserImpl::array_start()] virtual function

Source

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

The ::object-end signal is emitted each time a parser has successfully parsed an entire JSON object.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::object_end()][crate::subclass::prelude::ParserImpl::object_end()] virtual function

§object

the parsed JSON object

Source

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

The ::object-member signal is emitted each time a parser has successfully parsed a single member of a JSON object.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::object_member()][crate::subclass::prelude::ParserImpl::object_member()] virtual function

§object

the JSON object being parsed

§member_name

the name of the newly parsed member

Source

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

This signal is emitted each time a parser starts parsing a JSON object.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::object_start()][crate::subclass::prelude::ParserImpl::object_start()] virtual function

Source

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

This signal is emitted when a parser successfully finished parsing a JSON data stream.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::parse_end()][crate::subclass::prelude::ParserImpl::parse_end()] virtual function

Source

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

This signal is emitted when a parser starts parsing a JSON data stream.

§Deprecated since 1.10

Derive your own parser type from JsonParser and override the [ParserImpl::parse_start()][crate::subclass::prelude::ParserImpl::parse_start()] virtual function

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<O: IsA<Parser>> ParserExt for O