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