use crate::{ffi,Node};
use glib::{prelude::*,translate::*};
glib::wrapper! {
#[doc(alias = "JsonBuilder")]
pub struct Builder(Object<ffi::JsonBuilder, ffi::JsonBuilderClass>);
match fn {
type_ => || ffi::json_builder_get_type(),
}
}
impl Builder {
pub const NONE: Option<&'static Builder> = None;
#[doc(alias = "json_builder_new")]
pub fn new() -> Builder {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::json_builder_new())
}
}
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
#[doc(alias = "json_builder_new_immutable")]
pub fn new_immutable() -> Builder {
assert_initialized_main_thread!();
unsafe {
from_glib_full(ffi::json_builder_new_immutable())
}
}
pub fn builder() -> BuilderBuilder {
BuilderBuilder::new()
}
}
impl Default for Builder {
fn default() -> Self {
Self::new()
}
}
#[must_use = "The builder must be built to be used"]
pub struct BuilderBuilder {
builder: glib::object::ObjectBuilder<'static, Builder>,
}
impl BuilderBuilder {
fn new() -> Self {
Self { builder: glib::object::Object::builder() }
}
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
pub fn immutable(self, immutable: bool) -> Self {
Self { builder: self.builder.property("immutable", immutable), }
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Builder {
assert_initialized_main_thread!();
self.builder.build() }
}
pub trait BuilderExt: IsA<Builder> + 'static {
#[doc(alias = "json_builder_add_boolean_value")]
#[must_use]
fn add_boolean_value(&self, value: bool) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_add_boolean_value(self.as_ref().to_glib_none().0, value.into_glib()))
}
}
#[doc(alias = "json_builder_add_double_value")]
#[must_use]
fn add_double_value(&self, value: f64) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_add_double_value(self.as_ref().to_glib_none().0, value))
}
}
#[doc(alias = "json_builder_add_int_value")]
#[must_use]
fn add_int_value(&self, value: i64) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_add_int_value(self.as_ref().to_glib_none().0, value))
}
}
#[doc(alias = "json_builder_add_null_value")]
#[must_use]
fn add_null_value(&self) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_add_null_value(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "json_builder_add_string_value")]
#[must_use]
fn add_string_value(&self, value: &str) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_add_string_value(self.as_ref().to_glib_none().0, value.to_glib_none().0))
}
}
#[doc(alias = "json_builder_add_value")]
#[must_use]
fn add_value(&self, node: Node) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_add_value(self.as_ref().to_glib_none().0, node.into_glib_ptr()))
}
}
#[doc(alias = "json_builder_begin_array")]
#[must_use]
fn begin_array(&self) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_begin_array(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "json_builder_begin_object")]
#[must_use]
fn begin_object(&self) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_begin_object(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "json_builder_end_array")]
#[must_use]
fn end_array(&self) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_end_array(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "json_builder_end_object")]
#[must_use]
fn end_object(&self) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_end_object(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "json_builder_get_root")]
#[doc(alias = "get_root")]
fn root(&self) -> Option<Node> {
unsafe {
from_glib_full(ffi::json_builder_get_root(self.as_ref().to_glib_none().0))
}
}
#[doc(alias = "json_builder_reset")]
fn reset(&self) {
unsafe {
ffi::json_builder_reset(self.as_ref().to_glib_none().0);
}
}
#[doc(alias = "json_builder_set_member_name")]
#[must_use]
fn set_member_name(&self, member_name: &str) -> Option<Builder> {
unsafe {
from_glib_none(ffi::json_builder_set_member_name(self.as_ref().to_glib_none().0, member_name.to_glib_none().0))
}
}
#[cfg(feature = "v1_2")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
fn is_immutable(&self) -> bool {
ObjectExt::property(self.as_ref(), "immutable")
}
}
impl<O: IsA<Builder>> BuilderExt for O {}