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    #[doc(alias = "GDataOutputStream")]
15    pub struct DataOutputStream(Object<ffi::GDataOutputStream, ffi::GDataOutputStreamClass>) @extends FilterOutputStream, OutputStream, @implements Seekable;
16
17    match fn {
18        type_ => || ffi::g_data_output_stream_get_type(),
19    }
20}
21
22impl DataOutputStream {
23    pub const NONE: Option<&'static DataOutputStream> = None;
24
25    #[doc(alias = "g_data_output_stream_new")]
26    pub fn new(base_stream: &impl IsA<OutputStream>) -> DataOutputStream {
27        unsafe {
28            from_glib_full(ffi::g_data_output_stream_new(
29                base_stream.as_ref().to_glib_none().0,
30            ))
31        }
32    }
33
34    // rustdoc-stripper-ignore-next
35    /// Creates a new builder-pattern struct instance to construct [`DataOutputStream`] objects.
36    ///
37    /// This method returns an instance of [`DataOutputStreamBuilder`](crate::builders::DataOutputStreamBuilder) which can be used to create [`DataOutputStream`] objects.
38    pub fn builder() -> DataOutputStreamBuilder {
39        DataOutputStreamBuilder::new()
40    }
41}
42
43impl Default for DataOutputStream {
44    fn default() -> Self {
45        glib::object::Object::new::<Self>()
46    }
47}
48
49// rustdoc-stripper-ignore-next
50/// A [builder-pattern] type to construct [`DataOutputStream`] objects.
51///
52/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
53#[must_use = "The builder must be built to be used"]
54pub struct DataOutputStreamBuilder {
55    builder: glib::object::ObjectBuilder<'static, DataOutputStream>,
56}
57
58impl DataOutputStreamBuilder {
59    fn new() -> Self {
60        Self {
61            builder: glib::object::Object::builder(),
62        }
63    }
64
65    pub fn byte_order(self, byte_order: DataStreamByteOrder) -> Self {
66        Self {
67            builder: self.builder.property("byte-order", byte_order),
68        }
69    }
70
71    pub fn base_stream(self, base_stream: &impl IsA<OutputStream>) -> Self {
72        Self {
73            builder: self
74                .builder
75                .property("base-stream", base_stream.clone().upcast()),
76        }
77    }
78
79    pub fn close_base_stream(self, close_base_stream: bool) -> Self {
80        Self {
81            builder: self
82                .builder
83                .property("close-base-stream", close_base_stream),
84        }
85    }
86
87    // rustdoc-stripper-ignore-next
88    /// Build the [`DataOutputStream`].
89    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
90    pub fn build(self) -> DataOutputStream {
91        self.builder.build()
92    }
93}
94
95pub trait DataOutputStreamExt: IsA<DataOutputStream> + 'static {
96    #[doc(alias = "g_data_output_stream_get_byte_order")]
97    #[doc(alias = "get_byte_order")]
98    #[doc(alias = "byte-order")]
99    fn byte_order(&self) -> DataStreamByteOrder {
100        unsafe {
101            from_glib(ffi::g_data_output_stream_get_byte_order(
102                self.as_ref().to_glib_none().0,
103            ))
104        }
105    }
106
107    #[doc(alias = "g_data_output_stream_put_byte")]
108    fn put_byte(
109        &self,
110        data: u8,
111        cancellable: Option<&impl IsA<Cancellable>>,
112    ) -> Result<(), glib::Error> {
113        unsafe {
114            let mut error = std::ptr::null_mut();
115            let is_ok = ffi::g_data_output_stream_put_byte(
116                self.as_ref().to_glib_none().0,
117                data,
118                cancellable.map(|p| p.as_ref()).to_glib_none().0,
119                &mut error,
120            );
121            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
122            if error.is_null() {
123                Ok(())
124            } else {
125                Err(from_glib_full(error))
126            }
127        }
128    }
129
130    #[doc(alias = "g_data_output_stream_put_int16")]
131    fn put_int16(
132        &self,
133        data: i16,
134        cancellable: Option<&impl IsA<Cancellable>>,
135    ) -> Result<(), glib::Error> {
136        unsafe {
137            let mut error = std::ptr::null_mut();
138            let is_ok = ffi::g_data_output_stream_put_int16(
139                self.as_ref().to_glib_none().0,
140                data,
141                cancellable.map(|p| p.as_ref()).to_glib_none().0,
142                &mut error,
143            );
144            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
145            if error.is_null() {
146                Ok(())
147            } else {
148                Err(from_glib_full(error))
149            }
150        }
151    }
152
153    #[doc(alias = "g_data_output_stream_put_int32")]
154    fn put_int32(
155        &self,
156        data: i32,
157        cancellable: Option<&impl IsA<Cancellable>>,
158    ) -> Result<(), glib::Error> {
159        unsafe {
160            let mut error = std::ptr::null_mut();
161            let is_ok = ffi::g_data_output_stream_put_int32(
162                self.as_ref().to_glib_none().0,
163                data,
164                cancellable.map(|p| p.as_ref()).to_glib_none().0,
165                &mut error,
166            );
167            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
168            if error.is_null() {
169                Ok(())
170            } else {
171                Err(from_glib_full(error))
172            }
173        }
174    }
175
176    #[doc(alias = "g_data_output_stream_put_int64")]
177    fn put_int64(
178        &self,
179        data: i64,
180        cancellable: Option<&impl IsA<Cancellable>>,
181    ) -> Result<(), glib::Error> {
182        unsafe {
183            let mut error = std::ptr::null_mut();
184            let is_ok = ffi::g_data_output_stream_put_int64(
185                self.as_ref().to_glib_none().0,
186                data,
187                cancellable.map(|p| p.as_ref()).to_glib_none().0,
188                &mut error,
189            );
190            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
191            if error.is_null() {
192                Ok(())
193            } else {
194                Err(from_glib_full(error))
195            }
196        }
197    }
198
199    #[doc(alias = "g_data_output_stream_put_string")]
200    fn put_string(
201        &self,
202        str: &str,
203        cancellable: Option<&impl IsA<Cancellable>>,
204    ) -> Result<(), glib::Error> {
205        unsafe {
206            let mut error = std::ptr::null_mut();
207            let is_ok = ffi::g_data_output_stream_put_string(
208                self.as_ref().to_glib_none().0,
209                str.to_glib_none().0,
210                cancellable.map(|p| p.as_ref()).to_glib_none().0,
211                &mut error,
212            );
213            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
214            if error.is_null() {
215                Ok(())
216            } else {
217                Err(from_glib_full(error))
218            }
219        }
220    }
221
222    #[doc(alias = "g_data_output_stream_put_uint16")]
223    fn put_uint16(
224        &self,
225        data: u16,
226        cancellable: Option<&impl IsA<Cancellable>>,
227    ) -> Result<(), glib::Error> {
228        unsafe {
229            let mut error = std::ptr::null_mut();
230            let is_ok = ffi::g_data_output_stream_put_uint16(
231                self.as_ref().to_glib_none().0,
232                data,
233                cancellable.map(|p| p.as_ref()).to_glib_none().0,
234                &mut error,
235            );
236            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
237            if error.is_null() {
238                Ok(())
239            } else {
240                Err(from_glib_full(error))
241            }
242        }
243    }
244
245    #[doc(alias = "g_data_output_stream_put_uint32")]
246    fn put_uint32(
247        &self,
248        data: u32,
249        cancellable: Option<&impl IsA<Cancellable>>,
250    ) -> Result<(), glib::Error> {
251        unsafe {
252            let mut error = std::ptr::null_mut();
253            let is_ok = ffi::g_data_output_stream_put_uint32(
254                self.as_ref().to_glib_none().0,
255                data,
256                cancellable.map(|p| p.as_ref()).to_glib_none().0,
257                &mut error,
258            );
259            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
260            if error.is_null() {
261                Ok(())
262            } else {
263                Err(from_glib_full(error))
264            }
265        }
266    }
267
268    #[doc(alias = "g_data_output_stream_put_uint64")]
269    fn put_uint64(
270        &self,
271        data: u64,
272        cancellable: Option<&impl IsA<Cancellable>>,
273    ) -> Result<(), glib::Error> {
274        unsafe {
275            let mut error = std::ptr::null_mut();
276            let is_ok = ffi::g_data_output_stream_put_uint64(
277                self.as_ref().to_glib_none().0,
278                data,
279                cancellable.map(|p| p.as_ref()).to_glib_none().0,
280                &mut error,
281            );
282            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
283            if error.is_null() {
284                Ok(())
285            } else {
286                Err(from_glib_full(error))
287            }
288        }
289    }
290
291    #[doc(alias = "g_data_output_stream_set_byte_order")]
292    #[doc(alias = "byte-order")]
293    fn set_byte_order(&self, order: DataStreamByteOrder) {
294        unsafe {
295            ffi::g_data_output_stream_set_byte_order(
296                self.as_ref().to_glib_none().0,
297                order.into_glib(),
298            );
299        }
300    }
301
302    #[doc(alias = "byte-order")]
303    fn connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
304        unsafe extern "C" fn notify_byte_order_trampoline<
305            P: IsA<DataOutputStream>,
306            F: Fn(&P) + 'static,
307        >(
308            this: *mut ffi::GDataOutputStream,
309            _param_spec: glib::ffi::gpointer,
310            f: glib::ffi::gpointer,
311        ) {
312            let f: &F = &*(f as *const F);
313            f(DataOutputStream::from_glib_borrow(this).unsafe_cast_ref())
314        }
315        unsafe {
316            let f: Box_<F> = Box_::new(f);
317            connect_raw(
318                self.as_ptr() as *mut _,
319                c"notify::byte-order".as_ptr() as *const _,
320                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
321                    notify_byte_order_trampoline::<Self, F> as *const (),
322                )),
323                Box_::into_raw(f),
324            )
325        }
326    }
327}
328
329impl<O: IsA<DataOutputStream>> DataOutputStreamExt for O {}