json_glib/auto/serializable.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir
3// from gtk-girs (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi,Node};
7use glib::{prelude::*,translate::*};
8
9glib::wrapper! {
10 /// `JsonSerializable` is an interface for controlling the serialization
11 /// and deserialization of `GObject` classes.
12 ///
13 /// Implementing this interface allows controlling how the class is going
14 /// to be serialized or deserialized by `construct_gobject()` and
15 /// `serialize_gobject()`, respectively.
16 ///
17 /// # Implements
18 ///
19 /// [`SerializableExt`][trait@crate::prelude::SerializableExt]
20 #[doc(alias = "JsonSerializable")]
21 pub struct Serializable(Interface<ffi::JsonSerializable, ffi::JsonSerializableIface>);
22
23 match fn {
24 type_ => || ffi::json_serializable_get_type(),
25 }
26}
27
28impl Serializable {
29 pub const NONE: Option<&'static Serializable> = None;
30
31}
32
33/// Trait containing all [`struct@Serializable`] methods.
34///
35/// # Implementors
36///
37/// [`Serializable`][struct@crate::Serializable]
38pub trait SerializableExt: IsA<Serializable> + 'static {
39 /// Calls the default implementation of the `vfunc::Json::Serializable::deserialize_property`
40 /// virtual function.
41 ///
42 /// This function can be used inside a custom implementation of the
43 /// `deserialize_property()` virtual function in lieu of calling the
44 /// default implementation through `g_type_default_interface_peek()`:
45 ///
46 /// **⚠️ The following code is in c ⚠️**
47 ///
48 /// ```c
49 /// JsonSerializable *iface;
50 /// gboolean res;
51 ///
52 /// iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
53 /// res = iface->deserialize_property (serializable, property_name,
54 /// value,
55 /// pspec,
56 /// property_node);
57 /// ```
58 /// ## `property_name`
59 /// the name of the property to deserialize
60 /// ## `value`
61 /// a pointer to an uninitialized value
62 /// ## `pspec`
63 /// a property description
64 /// ## `property_node`
65 /// the JSON node containing the serialized property
66 ///
67 /// # Returns
68 ///
69 /// `TRUE` if the property was successfully deserialized
70 #[doc(alias = "json_serializable_default_deserialize_property")]
71 fn default_deserialize_property(&self, property_name: &str, value: &mut glib::Value, pspec: impl AsRef<glib::ParamSpec>, property_node: &Node) -> bool {
72 unsafe {
73 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))
74 }
75 }
76
77 /// Calls the default implementation of the `vfunc::Json::Serializable::serialize_property`
78 /// virtual function.
79 ///
80 /// This function can be used inside a custom implementation of the
81 /// `serialize_property()` virtual function in lieu of calling the
82 /// default implementation through `g_type_default_interface_peek()`:
83 ///
84 /// **⚠️ The following code is in c ⚠️**
85 ///
86 /// ```c
87 /// JsonSerializable *iface;
88 /// JsonNode *node;
89 ///
90 /// iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE);
91 /// node = iface->serialize_property (serializable, property_name,
92 /// value,
93 /// pspec);
94 /// ```
95 ///
96 /// This function will return `NULL` if the property could not be
97 /// serialized.
98 /// ## `property_name`
99 /// the name of the property to serialize
100 /// ## `value`
101 /// the value of the property to serialize
102 /// ## `pspec`
103 /// a property description
104 ///
105 /// # Returns
106 ///
107 /// a node containing the
108 /// serialized property
109 #[doc(alias = "json_serializable_default_serialize_property")]
110 fn default_serialize_property(&self, property_name: &str, value: &glib::Value, pspec: impl AsRef<glib::ParamSpec>) -> Option<Node> {
111 unsafe {
112 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))
113 }
114 }
115
116 /// Asks a `JsonSerializable` implementation to deserialize the
117 /// property contained inside `property_node` and place its value
118 /// into `value`.
119 ///
120 /// The `value` can be:
121 ///
122 /// - an empty `GValue` initialized by `G_VALUE_INIT`, which will be automatically
123 /// initialized with the expected type of the property by using the given
124 /// property description (since JSON-GLib 1.6)
125 /// - a `GValue` initialized with the expected type of the property
126 ///
127 /// This function will not be called for properties that are marked as
128 /// as `G_PARAM_CONSTRUCT_ONLY`.
129 /// ## `property_name`
130 /// the name of the property to serialize
131 /// ## `pspec`
132 /// a property description
133 /// ## `property_node`
134 /// the JSON node containing the serialized property
135 ///
136 /// # Returns
137 ///
138 /// `TRUE` if the property was successfully deserialized
139 ///
140 /// ## `value`
141 /// a pointer to an uninitialized value
142 #[doc(alias = "json_serializable_deserialize_property")]
143 fn deserialize_property(&self, property_name: &str, pspec: impl AsRef<glib::ParamSpec>, property_node: &Node) -> Option<glib::Value> {
144 unsafe {
145 let mut value = glib::Value::uninitialized();
146 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));
147 if ret { Some(value) } else { None }
148 }
149 }
150
151 /// Calls the `vfunc::Json::Serializable::find_property` implementation on
152 /// the `JsonSerializable` instance, which will return the property
153 /// description for the given name.
154 /// ## `name`
155 /// the name of the property
156 ///
157 /// # Returns
158 ///
159 /// the property description
160 #[doc(alias = "json_serializable_find_property")]
161 fn find_property(&self, name: &str) -> Option<glib::ParamSpec> {
162 unsafe {
163 from_glib_none(ffi::json_serializable_find_property(self.as_ref().to_glib_none().0, name.to_glib_none().0))
164 }
165 }
166
167 /// Calls the `vfunc::Json::Serializable::get_property` implementation
168 /// on the `JsonSerializable` instance, which will get the value of
169 /// the given property.
170 /// ## `pspec`
171 /// a property description
172 ///
173 /// # Returns
174 ///
175 ///
176 /// ## `value`
177 /// return location for the property value
178 #[doc(alias = "json_serializable_get_property")]
179 #[doc(alias = "get_property")]
180 fn property(&self, pspec: impl AsRef<glib::ParamSpec>) -> glib::Value {
181 unsafe {
182 let mut value = glib::Value::uninitialized();
183 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);
184 value
185 }
186 }
187
188 /// Calls the `vfunc::Json::Serializable::list_properties` implementation on
189 /// the `JsonSerializable` instance, which will return the list of serializable
190 /// properties.
191 ///
192 /// # Returns
193 ///
194 /// the serializable
195 /// properties of the object
196 #[doc(alias = "json_serializable_list_properties")]
197 fn list_properties(&self) -> Vec<glib::ParamSpec> {
198 unsafe {
199 let mut n_pspecs = std::mem::MaybeUninit::uninit();
200 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 _);
201 ret
202 }
203 }
204
205 /// Asks a `JsonSerializable` implementation to serialize an object
206 /// property into a JSON node.
207 /// ## `property_name`
208 /// the name of the property to serialize
209 /// ## `value`
210 /// the value of the property to serialize
211 /// ## `pspec`
212 /// a property description
213 ///
214 /// # Returns
215 ///
216 /// a node containing the serialized property
217 #[doc(alias = "json_serializable_serialize_property")]
218 fn serialize_property(&self, property_name: &str, value: &glib::Value, pspec: impl AsRef<glib::ParamSpec>) -> Option<Node> {
219 unsafe {
220 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))
221 }
222 }
223
224 /// Calls the `vfunc::Json::Serializable::set_property` implementation
225 /// on the `JsonSerializable` instance, which will set the property
226 /// with the given value.
227 /// ## `pspec`
228 /// a property description
229 /// ## `value`
230 /// the property value to set
231 #[doc(alias = "json_serializable_set_property")]
232 fn set_property(&self, pspec: impl AsRef<glib::ParamSpec>, value: &glib::Value) {
233 unsafe {
234 ffi::json_serializable_set_property(self.as_ref().to_glib_none().0, pspec.as_ref().to_glib_none().0, value.to_glib_none().0);
235 }
236 }
237}
238
239impl<O: IsA<Serializable>> SerializableExt for O {}