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
135mod sealed {
136    pub trait Sealed {}
137    impl<T: super::IsA<super::DataOutputStream>> Sealed for T {}
138}
139
140/// Trait containing all [`struct@DataOutputStream`] methods.
141///
142/// # Implementors
143///
144/// [`DataOutputStream`][struct@crate::DataOutputStream]
145pub trait DataOutputStreamExt: IsA<DataOutputStream> + sealed::Sealed + 'static {
146    /// Gets the byte order for the stream.
147    ///
148    /// # Returns
149    ///
150    /// the #GDataStreamByteOrder for the @self.
151    #[doc(alias = "g_data_output_stream_get_byte_order")]
152    #[doc(alias = "get_byte_order")]
153    #[doc(alias = "byte-order")]
154    fn byte_order(&self) -> DataStreamByteOrder {
155        unsafe {
156            from_glib(ffi::g_data_output_stream_get_byte_order(
157                self.as_ref().to_glib_none().0,
158            ))
159        }
160    }
161
162    /// Puts a byte into the output stream.
163    /// ## `data`
164    /// a #guchar.
165    /// ## `cancellable`
166    /// optional #GCancellable object, [`None`] to ignore.
167    ///
168    /// # Returns
169    ///
170    /// [`true`] if @data was successfully added to the @self.
171    #[doc(alias = "g_data_output_stream_put_byte")]
172    fn put_byte(
173        &self,
174        data: u8,
175        cancellable: Option<&impl IsA<Cancellable>>,
176    ) -> Result<(), glib::Error> {
177        unsafe {
178            let mut error = std::ptr::null_mut();
179            let is_ok = ffi::g_data_output_stream_put_byte(
180                self.as_ref().to_glib_none().0,
181                data,
182                cancellable.map(|p| p.as_ref()).to_glib_none().0,
183                &mut error,
184            );
185            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
186            if error.is_null() {
187                Ok(())
188            } else {
189                Err(from_glib_full(error))
190            }
191        }
192    }
193
194    /// Puts a signed 16-bit integer into the output stream.
195    /// ## `data`
196    /// a #gint16.
197    /// ## `cancellable`
198    /// optional #GCancellable object, [`None`] to ignore.
199    ///
200    /// # Returns
201    ///
202    /// [`true`] if @data was successfully added to the @self.
203    #[doc(alias = "g_data_output_stream_put_int16")]
204    fn put_int16(
205        &self,
206        data: i16,
207        cancellable: Option<&impl IsA<Cancellable>>,
208    ) -> Result<(), glib::Error> {
209        unsafe {
210            let mut error = std::ptr::null_mut();
211            let is_ok = ffi::g_data_output_stream_put_int16(
212                self.as_ref().to_glib_none().0,
213                data,
214                cancellable.map(|p| p.as_ref()).to_glib_none().0,
215                &mut error,
216            );
217            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
218            if error.is_null() {
219                Ok(())
220            } else {
221                Err(from_glib_full(error))
222            }
223        }
224    }
225
226    /// Puts a signed 32-bit integer into the output stream.
227    /// ## `data`
228    /// a #gint32.
229    /// ## `cancellable`
230    /// optional #GCancellable object, [`None`] to ignore.
231    ///
232    /// # Returns
233    ///
234    /// [`true`] if @data was successfully added to the @self.
235    #[doc(alias = "g_data_output_stream_put_int32")]
236    fn put_int32(
237        &self,
238        data: i32,
239        cancellable: Option<&impl IsA<Cancellable>>,
240    ) -> Result<(), glib::Error> {
241        unsafe {
242            let mut error = std::ptr::null_mut();
243            let is_ok = ffi::g_data_output_stream_put_int32(
244                self.as_ref().to_glib_none().0,
245                data,
246                cancellable.map(|p| p.as_ref()).to_glib_none().0,
247                &mut error,
248            );
249            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
250            if error.is_null() {
251                Ok(())
252            } else {
253                Err(from_glib_full(error))
254            }
255        }
256    }
257
258    /// Puts a signed 64-bit integer into the stream.
259    /// ## `data`
260    /// a #gint64.
261    /// ## `cancellable`
262    /// optional #GCancellable object, [`None`] to ignore.
263    ///
264    /// # Returns
265    ///
266    /// [`true`] if @data was successfully added to the @self.
267    #[doc(alias = "g_data_output_stream_put_int64")]
268    fn put_int64(
269        &self,
270        data: i64,
271        cancellable: Option<&impl IsA<Cancellable>>,
272    ) -> Result<(), glib::Error> {
273        unsafe {
274            let mut error = std::ptr::null_mut();
275            let is_ok = ffi::g_data_output_stream_put_int64(
276                self.as_ref().to_glib_none().0,
277                data,
278                cancellable.map(|p| p.as_ref()).to_glib_none().0,
279                &mut error,
280            );
281            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
282            if error.is_null() {
283                Ok(())
284            } else {
285                Err(from_glib_full(error))
286            }
287        }
288    }
289
290    /// Puts a string into the output stream.
291    /// ## `str`
292    /// a string.
293    /// ## `cancellable`
294    /// optional #GCancellable object, [`None`] to ignore.
295    ///
296    /// # Returns
297    ///
298    /// [`true`] if @string was successfully added to the @self.
299    #[doc(alias = "g_data_output_stream_put_string")]
300    fn put_string(
301        &self,
302        str: &str,
303        cancellable: Option<&impl IsA<Cancellable>>,
304    ) -> Result<(), glib::Error> {
305        unsafe {
306            let mut error = std::ptr::null_mut();
307            let is_ok = ffi::g_data_output_stream_put_string(
308                self.as_ref().to_glib_none().0,
309                str.to_glib_none().0,
310                cancellable.map(|p| p.as_ref()).to_glib_none().0,
311                &mut error,
312            );
313            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
314            if error.is_null() {
315                Ok(())
316            } else {
317                Err(from_glib_full(error))
318            }
319        }
320    }
321
322    /// Puts an unsigned 16-bit integer into the output stream.
323    /// ## `data`
324    /// a #guint16.
325    /// ## `cancellable`
326    /// optional #GCancellable object, [`None`] to ignore.
327    ///
328    /// # Returns
329    ///
330    /// [`true`] if @data was successfully added to the @self.
331    #[doc(alias = "g_data_output_stream_put_uint16")]
332    fn put_uint16(
333        &self,
334        data: u16,
335        cancellable: Option<&impl IsA<Cancellable>>,
336    ) -> Result<(), glib::Error> {
337        unsafe {
338            let mut error = std::ptr::null_mut();
339            let is_ok = ffi::g_data_output_stream_put_uint16(
340                self.as_ref().to_glib_none().0,
341                data,
342                cancellable.map(|p| p.as_ref()).to_glib_none().0,
343                &mut error,
344            );
345            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
346            if error.is_null() {
347                Ok(())
348            } else {
349                Err(from_glib_full(error))
350            }
351        }
352    }
353
354    /// Puts an unsigned 32-bit integer into the stream.
355    /// ## `data`
356    /// a #guint32.
357    /// ## `cancellable`
358    /// optional #GCancellable object, [`None`] to ignore.
359    ///
360    /// # Returns
361    ///
362    /// [`true`] if @data was successfully added to the @self.
363    #[doc(alias = "g_data_output_stream_put_uint32")]
364    fn put_uint32(
365        &self,
366        data: u32,
367        cancellable: Option<&impl IsA<Cancellable>>,
368    ) -> Result<(), glib::Error> {
369        unsafe {
370            let mut error = std::ptr::null_mut();
371            let is_ok = ffi::g_data_output_stream_put_uint32(
372                self.as_ref().to_glib_none().0,
373                data,
374                cancellable.map(|p| p.as_ref()).to_glib_none().0,
375                &mut error,
376            );
377            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
378            if error.is_null() {
379                Ok(())
380            } else {
381                Err(from_glib_full(error))
382            }
383        }
384    }
385
386    /// Puts an unsigned 64-bit integer into the stream.
387    /// ## `data`
388    /// a #guint64.
389    /// ## `cancellable`
390    /// optional #GCancellable object, [`None`] to ignore.
391    ///
392    /// # Returns
393    ///
394    /// [`true`] if @data was successfully added to the @self.
395    #[doc(alias = "g_data_output_stream_put_uint64")]
396    fn put_uint64(
397        &self,
398        data: u64,
399        cancellable: Option<&impl IsA<Cancellable>>,
400    ) -> Result<(), glib::Error> {
401        unsafe {
402            let mut error = std::ptr::null_mut();
403            let is_ok = ffi::g_data_output_stream_put_uint64(
404                self.as_ref().to_glib_none().0,
405                data,
406                cancellable.map(|p| p.as_ref()).to_glib_none().0,
407                &mut error,
408            );
409            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
410            if error.is_null() {
411                Ok(())
412            } else {
413                Err(from_glib_full(error))
414            }
415        }
416    }
417
418    /// Sets the byte order of the data output stream to @order.
419    /// ## `order`
420    /// a `GDataStreamByteOrder`.
421    #[doc(alias = "g_data_output_stream_set_byte_order")]
422    #[doc(alias = "byte-order")]
423    fn set_byte_order(&self, order: DataStreamByteOrder) {
424        unsafe {
425            ffi::g_data_output_stream_set_byte_order(
426                self.as_ref().to_glib_none().0,
427                order.into_glib(),
428            );
429        }
430    }
431
432    #[doc(alias = "byte-order")]
433    fn connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
434        unsafe extern "C" fn notify_byte_order_trampoline<
435            P: IsA<DataOutputStream>,
436            F: Fn(&P) + 'static,
437        >(
438            this: *mut ffi::GDataOutputStream,
439            _param_spec: glib::ffi::gpointer,
440            f: glib::ffi::gpointer,
441        ) {
442            let f: &F = &*(f as *const F);
443            f(DataOutputStream::from_glib_borrow(this).unsafe_cast_ref())
444        }
445        unsafe {
446            let f: Box_<F> = Box_::new(f);
447            connect_raw(
448                self.as_ptr() as *mut _,
449                b"notify::byte-order\0".as_ptr() as *const _,
450                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
451                    notify_byte_order_trampoline::<Self, F> as *const (),
452                )),
453                Box_::into_raw(f),
454            )
455        }
456    }
457}
458
459impl<O: IsA<DataOutputStream>> DataOutputStreamExt for O {}