gio/auto/
data_output_stream.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Cancellable, DataStreamByteOrder, FilterOutputStream, OutputStream, Seekable};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// Data output stream implements [`OutputStream`][crate::OutputStream] and includes functions
15    /// for writing data directly to an output stream.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `byte-order`
21    ///  Determines the byte ordering that is used when writing
22    /// multi-byte entities (such as integers) to the stream.
23    ///
24    /// Readable | Writeable
25    /// <details><summary><h4>FilterOutputStream</h4></summary>
26    ///
27    ///
28    /// #### `base-stream`
29    ///  The underlying base stream on which the I/O ops will be done.
30    ///
31    /// Readable | Writeable | Construct Only
32    ///
33    ///
34    /// #### `close-base-stream`
35    ///  Whether the base stream should be closed when the filter stream is closed.
36    ///
37    /// Readable | Writeable | Construct Only
38    /// </details>
39    ///
40    /// # Implements
41    ///
42    /// [`DataOutputStreamExt`][trait@crate::prelude::DataOutputStreamExt], [`FilterOutputStreamExt`][trait@crate::prelude::FilterOutputStreamExt], [`OutputStreamExt`][trait@crate::prelude::OutputStreamExt], [`trait@glib::ObjectExt`], [`SeekableExt`][trait@crate::prelude::SeekableExt], [`OutputStreamExtManual`][trait@crate::prelude::OutputStreamExtManual]
43    #[doc(alias = "GDataOutputStream")]
44    pub struct DataOutputStream(Object<ffi::GDataOutputStream, ffi::GDataOutputStreamClass>) @extends FilterOutputStream, OutputStream, @implements Seekable;
45
46    match fn {
47        type_ => || ffi::g_data_output_stream_get_type(),
48    }
49}
50
51impl DataOutputStream {
52    pub const NONE: Option<&'static DataOutputStream> = None;
53
54    /// Creates a new data output stream for @base_stream.
55    /// ## `base_stream`
56    /// a #GOutputStream.
57    ///
58    /// # Returns
59    ///
60    /// #GDataOutputStream.
61    #[doc(alias = "g_data_output_stream_new")]
62    pub fn new(base_stream: &impl IsA<OutputStream>) -> DataOutputStream {
63        unsafe {
64            from_glib_full(ffi::g_data_output_stream_new(
65                base_stream.as_ref().to_glib_none().0,
66            ))
67        }
68    }
69
70    // rustdoc-stripper-ignore-next
71    /// Creates a new builder-pattern struct instance to construct [`DataOutputStream`] objects.
72    ///
73    /// This method returns an instance of [`DataOutputStreamBuilder`](crate::builders::DataOutputStreamBuilder) which can be used to create [`DataOutputStream`] objects.
74    pub fn builder() -> DataOutputStreamBuilder {
75        DataOutputStreamBuilder::new()
76    }
77}
78
79impl Default for DataOutputStream {
80    fn default() -> Self {
81        glib::object::Object::new::<Self>()
82    }
83}
84
85// rustdoc-stripper-ignore-next
86/// A [builder-pattern] type to construct [`DataOutputStream`] objects.
87///
88/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
89#[must_use = "The builder must be built to be used"]
90pub struct DataOutputStreamBuilder {
91    builder: glib::object::ObjectBuilder<'static, DataOutputStream>,
92}
93
94impl DataOutputStreamBuilder {
95    fn new() -> Self {
96        Self {
97            builder: glib::object::Object::builder(),
98        }
99    }
100
101    /// Determines the byte ordering that is used when writing
102    /// multi-byte entities (such as integers) to the stream.
103    pub fn byte_order(self, byte_order: DataStreamByteOrder) -> Self {
104        Self {
105            builder: self.builder.property("byte-order", byte_order),
106        }
107    }
108
109    /// The underlying base stream on which the I/O ops will be done.
110    pub fn base_stream(self, base_stream: &impl IsA<OutputStream>) -> Self {
111        Self {
112            builder: self
113                .builder
114                .property("base-stream", base_stream.clone().upcast()),
115        }
116    }
117
118    /// Whether the base stream should be closed when the filter stream is closed.
119    pub fn close_base_stream(self, close_base_stream: bool) -> Self {
120        Self {
121            builder: self
122                .builder
123                .property("close-base-stream", close_base_stream),
124        }
125    }
126
127    // rustdoc-stripper-ignore-next
128    /// Build the [`DataOutputStream`].
129    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
130    pub fn build(self) -> DataOutputStream {
131        self.builder.build()
132    }
133}
134
135/// Trait containing all [`struct@DataOutputStream`] methods.
136///
137/// # Implementors
138///
139/// [`DataOutputStream`][struct@crate::DataOutputStream]
140pub trait DataOutputStreamExt: IsA<DataOutputStream> + 'static {
141    /// Gets the byte order for the stream.
142    ///
143    /// # Returns
144    ///
145    /// the #GDataStreamByteOrder for the @self.
146    #[doc(alias = "g_data_output_stream_get_byte_order")]
147    #[doc(alias = "get_byte_order")]
148    #[doc(alias = "byte-order")]
149    fn byte_order(&self) -> DataStreamByteOrder {
150        unsafe {
151            from_glib(ffi::g_data_output_stream_get_byte_order(
152                self.as_ref().to_glib_none().0,
153            ))
154        }
155    }
156
157    /// Puts a byte into the output stream.
158    /// ## `data`
159    /// a #guchar.
160    /// ## `cancellable`
161    /// optional #GCancellable object, [`None`] to ignore.
162    ///
163    /// # Returns
164    ///
165    /// [`true`] if @data was successfully added to the @self.
166    #[doc(alias = "g_data_output_stream_put_byte")]
167    fn put_byte(
168        &self,
169        data: u8,
170        cancellable: Option<&impl IsA<Cancellable>>,
171    ) -> Result<(), glib::Error> {
172        unsafe {
173            let mut error = std::ptr::null_mut();
174            let is_ok = ffi::g_data_output_stream_put_byte(
175                self.as_ref().to_glib_none().0,
176                data,
177                cancellable.map(|p| p.as_ref()).to_glib_none().0,
178                &mut error,
179            );
180            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
181            if error.is_null() {
182                Ok(())
183            } else {
184                Err(from_glib_full(error))
185            }
186        }
187    }
188
189    /// Puts a signed 16-bit integer into the output stream.
190    /// ## `data`
191    /// a #gint16.
192    /// ## `cancellable`
193    /// optional #GCancellable object, [`None`] to ignore.
194    ///
195    /// # Returns
196    ///
197    /// [`true`] if @data was successfully added to the @self.
198    #[doc(alias = "g_data_output_stream_put_int16")]
199    fn put_int16(
200        &self,
201        data: i16,
202        cancellable: Option<&impl IsA<Cancellable>>,
203    ) -> Result<(), glib::Error> {
204        unsafe {
205            let mut error = std::ptr::null_mut();
206            let is_ok = ffi::g_data_output_stream_put_int16(
207                self.as_ref().to_glib_none().0,
208                data,
209                cancellable.map(|p| p.as_ref()).to_glib_none().0,
210                &mut error,
211            );
212            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
213            if error.is_null() {
214                Ok(())
215            } else {
216                Err(from_glib_full(error))
217            }
218        }
219    }
220
221    /// Puts a signed 32-bit integer into the output stream.
222    /// ## `data`
223    /// a #gint32.
224    /// ## `cancellable`
225    /// optional #GCancellable object, [`None`] to ignore.
226    ///
227    /// # Returns
228    ///
229    /// [`true`] if @data was successfully added to the @self.
230    #[doc(alias = "g_data_output_stream_put_int32")]
231    fn put_int32(
232        &self,
233        data: i32,
234        cancellable: Option<&impl IsA<Cancellable>>,
235    ) -> Result<(), glib::Error> {
236        unsafe {
237            let mut error = std::ptr::null_mut();
238            let is_ok = ffi::g_data_output_stream_put_int32(
239                self.as_ref().to_glib_none().0,
240                data,
241                cancellable.map(|p| p.as_ref()).to_glib_none().0,
242                &mut error,
243            );
244            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
245            if error.is_null() {
246                Ok(())
247            } else {
248                Err(from_glib_full(error))
249            }
250        }
251    }
252
253    /// Puts a signed 64-bit integer into the stream.
254    /// ## `data`
255    /// a #gint64.
256    /// ## `cancellable`
257    /// optional #GCancellable object, [`None`] to ignore.
258    ///
259    /// # Returns
260    ///
261    /// [`true`] if @data was successfully added to the @self.
262    #[doc(alias = "g_data_output_stream_put_int64")]
263    fn put_int64(
264        &self,
265        data: i64,
266        cancellable: Option<&impl IsA<Cancellable>>,
267    ) -> Result<(), glib::Error> {
268        unsafe {
269            let mut error = std::ptr::null_mut();
270            let is_ok = ffi::g_data_output_stream_put_int64(
271                self.as_ref().to_glib_none().0,
272                data,
273                cancellable.map(|p| p.as_ref()).to_glib_none().0,
274                &mut error,
275            );
276            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
277            if error.is_null() {
278                Ok(())
279            } else {
280                Err(from_glib_full(error))
281            }
282        }
283    }
284
285    /// Puts a string into the output stream.
286    /// ## `str`
287    /// a string.
288    /// ## `cancellable`
289    /// optional #GCancellable object, [`None`] to ignore.
290    ///
291    /// # Returns
292    ///
293    /// [`true`] if @string was successfully added to the @self.
294    #[doc(alias = "g_data_output_stream_put_string")]
295    fn put_string(
296        &self,
297        str: &str,
298        cancellable: Option<&impl IsA<Cancellable>>,
299    ) -> Result<(), glib::Error> {
300        unsafe {
301            let mut error = std::ptr::null_mut();
302            let is_ok = ffi::g_data_output_stream_put_string(
303                self.as_ref().to_glib_none().0,
304                str.to_glib_none().0,
305                cancellable.map(|p| p.as_ref()).to_glib_none().0,
306                &mut error,
307            );
308            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
309            if error.is_null() {
310                Ok(())
311            } else {
312                Err(from_glib_full(error))
313            }
314        }
315    }
316
317    /// Puts an unsigned 16-bit integer into the output stream.
318    /// ## `data`
319    /// a #guint16.
320    /// ## `cancellable`
321    /// optional #GCancellable object, [`None`] to ignore.
322    ///
323    /// # Returns
324    ///
325    /// [`true`] if @data was successfully added to the @self.
326    #[doc(alias = "g_data_output_stream_put_uint16")]
327    fn put_uint16(
328        &self,
329        data: u16,
330        cancellable: Option<&impl IsA<Cancellable>>,
331    ) -> Result<(), glib::Error> {
332        unsafe {
333            let mut error = std::ptr::null_mut();
334            let is_ok = ffi::g_data_output_stream_put_uint16(
335                self.as_ref().to_glib_none().0,
336                data,
337                cancellable.map(|p| p.as_ref()).to_glib_none().0,
338                &mut error,
339            );
340            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
341            if error.is_null() {
342                Ok(())
343            } else {
344                Err(from_glib_full(error))
345            }
346        }
347    }
348
349    /// Puts an unsigned 32-bit integer into the stream.
350    /// ## `data`
351    /// a #guint32.
352    /// ## `cancellable`
353    /// optional #GCancellable object, [`None`] to ignore.
354    ///
355    /// # Returns
356    ///
357    /// [`true`] if @data was successfully added to the @self.
358    #[doc(alias = "g_data_output_stream_put_uint32")]
359    fn put_uint32(
360        &self,
361        data: u32,
362        cancellable: Option<&impl IsA<Cancellable>>,
363    ) -> Result<(), glib::Error> {
364        unsafe {
365            let mut error = std::ptr::null_mut();
366            let is_ok = ffi::g_data_output_stream_put_uint32(
367                self.as_ref().to_glib_none().0,
368                data,
369                cancellable.map(|p| p.as_ref()).to_glib_none().0,
370                &mut error,
371            );
372            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
373            if error.is_null() {
374                Ok(())
375            } else {
376                Err(from_glib_full(error))
377            }
378        }
379    }
380
381    /// Puts an unsigned 64-bit integer into the stream.
382    /// ## `data`
383    /// a #guint64.
384    /// ## `cancellable`
385    /// optional #GCancellable object, [`None`] to ignore.
386    ///
387    /// # Returns
388    ///
389    /// [`true`] if @data was successfully added to the @self.
390    #[doc(alias = "g_data_output_stream_put_uint64")]
391    fn put_uint64(
392        &self,
393        data: u64,
394        cancellable: Option<&impl IsA<Cancellable>>,
395    ) -> Result<(), glib::Error> {
396        unsafe {
397            let mut error = std::ptr::null_mut();
398            let is_ok = ffi::g_data_output_stream_put_uint64(
399                self.as_ref().to_glib_none().0,
400                data,
401                cancellable.map(|p| p.as_ref()).to_glib_none().0,
402                &mut error,
403            );
404            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
405            if error.is_null() {
406                Ok(())
407            } else {
408                Err(from_glib_full(error))
409            }
410        }
411    }
412
413    /// Sets the byte order of the data output stream to @order.
414    /// ## `order`
415    /// a `GDataStreamByteOrder`.
416    #[doc(alias = "g_data_output_stream_set_byte_order")]
417    #[doc(alias = "byte-order")]
418    fn set_byte_order(&self, order: DataStreamByteOrder) {
419        unsafe {
420            ffi::g_data_output_stream_set_byte_order(
421                self.as_ref().to_glib_none().0,
422                order.into_glib(),
423            );
424        }
425    }
426
427    #[doc(alias = "byte-order")]
428    fn connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
429        unsafe extern "C" fn notify_byte_order_trampoline<
430            P: IsA<DataOutputStream>,
431            F: Fn(&P) + 'static,
432        >(
433            this: *mut ffi::GDataOutputStream,
434            _param_spec: glib::ffi::gpointer,
435            f: glib::ffi::gpointer,
436        ) {
437            let f: &F = &*(f as *const F);
438            f(DataOutputStream::from_glib_borrow(this).unsafe_cast_ref())
439        }
440        unsafe {
441            let f: Box_<F> = Box_::new(f);
442            connect_raw(
443                self.as_ptr() as *mut _,
444                c"notify::byte-order".as_ptr() as *const _,
445                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
446                    notify_byte_order_trampoline::<Self, F> as *const (),
447                )),
448                Box_::into_raw(f),
449            )
450        }
451    }
452}
453
454impl<O: IsA<DataOutputStream>> DataOutputStreamExt for O {}