json-glib 0.1.1

Rust bindings for the Glib Json library
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir
// from gtk-girs (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi,Node};
use glib::{prelude::*,translate::*};

glib::wrapper! {
    /// `JsonSerializable` is an interface for controlling the serialization
    /// and deserialization of `GObject` classes.
    ///
    /// Implementing this interface allows controlling how the class is going
    /// to be serialized or deserialized by `construct_gobject()` and
    /// `serialize_gobject()`, respectively.
    ///
    /// # Implements
    ///
    /// [`SerializableExt`][trait@crate::prelude::SerializableExt]
    #[doc(alias = "JsonSerializable")]
    pub struct Serializable(Interface<ffi::JsonSerializable, ffi::JsonSerializableIface>);

    match fn {
        type_ => || ffi::json_serializable_get_type(),
    }
}

impl Serializable {
        pub const NONE: Option<&'static Serializable> = None;
    
}

/// Trait containing all [`struct@Serializable`] methods.
///
/// # Implementors
///
/// [`Serializable`][struct@crate::Serializable]
pub trait SerializableExt: IsA<Serializable> + 'static {
    /// Calls the default implementation of the `vfunc::Json::Serializable::deserialize_property`
    /// virtual function.
    ///
    /// This function can be used inside a custom implementation of the
    /// `deserialize_property()` virtual function in lieu of calling the
    /// default implementation through `g_type_default_interface_peek()`:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// JsonSerializable *iface;
    /// gboolean res;
    ///
    /// iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
    /// res = iface->deserialize_property (serializable, property_name,
    ///                                    value,
    ///                                    pspec,
    ///                                    property_node);
    /// ```
    /// ## `property_name`
    /// the name of the property to deserialize
    /// ## `value`
    /// a pointer to an uninitialized value
    /// ## `pspec`
    /// a property description
    /// ## `property_node`
    /// the JSON node containing the serialized property
    ///
    /// # Returns
    ///
    /// `TRUE` if the property was successfully deserialized
    #[doc(alias = "json_serializable_default_deserialize_property")]
    fn default_deserialize_property(&self, property_name: &str, value: &mut glib::Value, pspec: impl AsRef<glib::ParamSpec>, property_node: &Node) -> bool {
        unsafe {
            from_glib(ffi::json_serializable_default_deserialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none_mut().0, pspec.as_ref().to_glib_none().0, property_node.to_glib_none().0))
        }
    }

    /// Calls the default implementation of the `vfunc::Json::Serializable::serialize_property`
    /// virtual function.
    ///
    /// This function can be used inside a custom implementation of the
    /// `serialize_property()` virtual function in lieu of calling the
    /// default implementation through `g_type_default_interface_peek()`:
    ///
    /// **⚠️ The following code is in c ⚠️**
    ///
    /// ```c
    /// JsonSerializable *iface;
    /// JsonNode *node;
    ///
    /// iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
    /// node = iface->serialize_property (serializable, property_name,
    ///                                   value,
    ///                                   pspec);
    /// ```
    ///
    /// This function will return `NULL` if the property could not be
    /// serialized.
    /// ## `property_name`
    /// the name of the property to serialize
    /// ## `value`
    /// the value of the property to serialize
    /// ## `pspec`
    /// a property description
    ///
    /// # Returns
    ///
    /// a node containing the
    ///   serialized property
    #[doc(alias = "json_serializable_default_serialize_property")]
    fn default_serialize_property(&self, property_name: &str, value: &glib::Value, pspec: impl AsRef<glib::ParamSpec>) -> Option<Node> {
        unsafe {
            from_glib_full(ffi::json_serializable_default_serialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none().0, pspec.as_ref().to_glib_none().0))
        }
    }

    /// Asks a `JsonSerializable` implementation to deserialize the
    /// property contained inside `property_node` and place its value
    /// into `value`.
    ///
    /// The `value` can be:
    ///
    /// - an empty `GValue` initialized by `G_VALUE_INIT`, which will be automatically
    ///   initialized with the expected type of the property by using the given
    ///   property description (since JSON-GLib 1.6)
    /// - a `GValue` initialized with the expected type of the property
    ///
    /// This function will not be called for properties that are marked as
    /// as `G_PARAM_CONSTRUCT_ONLY`.
    /// ## `property_name`
    /// the name of the property to serialize
    /// ## `pspec`
    /// a property description
    /// ## `property_node`
    /// the JSON node containing the serialized property
    ///
    /// # Returns
    ///
    /// `TRUE` if the property was successfully deserialized
    ///
    /// ## `value`
    /// a pointer to an uninitialized value
    #[doc(alias = "json_serializable_deserialize_property")]
    fn deserialize_property(&self, property_name: &str, pspec: impl AsRef<glib::ParamSpec>, property_node: &Node) -> Option<glib::Value> {
        unsafe {
            let mut value = glib::Value::uninitialized();
            let ret = from_glib(ffi::json_serializable_deserialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none_mut().0, pspec.as_ref().to_glib_none().0, property_node.to_glib_none().0));
            if ret { Some(value) } else { None }
        }
    }

    /// Calls the `vfunc::Json::Serializable::find_property` implementation on
    /// the `JsonSerializable` instance, which will return the property
    /// description for the given name.
    /// ## `name`
    /// the name of the property
    ///
    /// # Returns
    ///
    /// the property description
    #[doc(alias = "json_serializable_find_property")]
    fn find_property(&self, name: &str) -> Option<glib::ParamSpec> {
        unsafe {
            from_glib_none(ffi::json_serializable_find_property(self.as_ref().to_glib_none().0, name.to_glib_none().0))
        }
    }

    /// Calls the `vfunc::Json::Serializable::get_property` implementation
    /// on the `JsonSerializable` instance, which will get the value of
    /// the given property.
    /// ## `pspec`
    /// a property description
    ///
    /// # Returns
    ///
    ///
    /// ## `value`
    /// return location for the property value
    #[doc(alias = "json_serializable_get_property")]
    #[doc(alias = "get_property")]
    fn property(&self, pspec: impl AsRef<glib::ParamSpec>) -> glib::Value {
        unsafe {
            let mut value = glib::Value::uninitialized();
            ffi::json_serializable_get_property(self.as_ref().to_glib_none().0, pspec.as_ref().to_glib_none().0, value.to_glib_none_mut().0);
            value
        }
    }

    /// Calls the `vfunc::Json::Serializable::list_properties` implementation on
    /// the `JsonSerializable` instance, which will return the list of serializable
    /// properties.
    ///
    /// # Returns
    ///
    /// the serializable
    ///   properties of the object
    #[doc(alias = "json_serializable_list_properties")]
    fn list_properties(&self) -> Vec<glib::ParamSpec> {
        unsafe {
            let mut n_pspecs = std::mem::MaybeUninit::uninit();
            let ret = FromGlibContainer::from_glib_container_num(ffi::json_serializable_list_properties(self.as_ref().to_glib_none().0, n_pspecs.as_mut_ptr()), n_pspecs.assume_init() as _);
            ret
        }
    }

    /// Asks a `JsonSerializable` implementation to serialize an object
    /// property into a JSON node.
    /// ## `property_name`
    /// the name of the property to serialize
    /// ## `value`
    /// the value of the property to serialize
    /// ## `pspec`
    /// a property description
    ///
    /// # Returns
    ///
    /// a node containing the serialized property
    #[doc(alias = "json_serializable_serialize_property")]
    fn serialize_property(&self, property_name: &str, value: &glib::Value, pspec: impl AsRef<glib::ParamSpec>) -> Option<Node> {
        unsafe {
            from_glib_full(ffi::json_serializable_serialize_property(self.as_ref().to_glib_none().0, property_name.to_glib_none().0, value.to_glib_none().0, pspec.as_ref().to_glib_none().0))
        }
    }

    /// Calls the `vfunc::Json::Serializable::set_property` implementation
    /// on the `JsonSerializable` instance, which will set the property
    /// with the given value.
    /// ## `pspec`
    /// a property description
    /// ## `value`
    /// the property value to set
    #[doc(alias = "json_serializable_set_property")]
    fn set_property(&self, pspec: impl AsRef<glib::ParamSpec>, value: &glib::Value) {
        unsafe {
            ffi::json_serializable_set_property(self.as_ref().to_glib_none().0, pspec.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }
}

impl<O: IsA<Serializable>> SerializableExt for O {}