gio/auto/
converter_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::{ffi, Converter, FilterInputStream, InputStream, PollableInputStream};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// Converter input stream implements [`InputStream`][crate::InputStream] and allows
10    /// conversion of data of various types during reading.
11    ///
12    /// As of GLib 2.34, `GConverterInputStream` implements
13    /// [`PollableInputStream`][crate::PollableInputStream].
14    ///
15    /// ## Properties
16    ///
17    ///
18    /// #### `converter`
19    ///  The converter object.
20    ///
21    /// Readable | Writeable | Construct Only
22    /// <details><summary><h4>FilterInputStream</h4></summary>
23    ///
24    ///
25    /// #### `base-stream`
26    ///  The underlying base stream on which the I/O ops will be done.
27    ///
28    /// Readable | Writeable | Construct Only
29    ///
30    ///
31    /// #### `close-base-stream`
32    ///  Whether the base stream should be closed when the filter stream is closed.
33    ///
34    /// Readable | Writeable | Construct
35    /// </details>
36    ///
37    /// # Implements
38    ///
39    /// [`ConverterInputStreamExt`][trait@crate::prelude::ConverterInputStreamExt], [`FilterInputStreamExt`][trait@crate::prelude::FilterInputStreamExt], [`InputStreamExt`][trait@crate::prelude::InputStreamExt], [`trait@glib::ObjectExt`], [`PollableInputStreamExt`][trait@crate::prelude::PollableInputStreamExt], [`InputStreamExtManual`][trait@crate::prelude::InputStreamExtManual], [`PollableInputStreamExtManual`][trait@crate::prelude::PollableInputStreamExtManual]
40    #[doc(alias = "GConverterInputStream")]
41    pub struct ConverterInputStream(Object<ffi::GConverterInputStream, ffi::GConverterInputStreamClass>) @extends FilterInputStream, InputStream, @implements PollableInputStream;
42
43    match fn {
44        type_ => || ffi::g_converter_input_stream_get_type(),
45    }
46}
47
48impl ConverterInputStream {
49    pub const NONE: Option<&'static ConverterInputStream> = None;
50
51    /// Creates a new converter input stream for the @base_stream.
52    /// ## `base_stream`
53    /// a #GInputStream
54    /// ## `converter`
55    /// a #GConverter
56    ///
57    /// # Returns
58    ///
59    /// a new #GInputStream.
60    #[doc(alias = "g_converter_input_stream_new")]
61    pub fn new(
62        base_stream: &impl IsA<InputStream>,
63        converter: &impl IsA<Converter>,
64    ) -> ConverterInputStream {
65        unsafe {
66            InputStream::from_glib_full(ffi::g_converter_input_stream_new(
67                base_stream.as_ref().to_glib_none().0,
68                converter.as_ref().to_glib_none().0,
69            ))
70            .unsafe_cast()
71        }
72    }
73
74    // rustdoc-stripper-ignore-next
75    /// Creates a new builder-pattern struct instance to construct [`ConverterInputStream`] objects.
76    ///
77    /// This method returns an instance of [`ConverterInputStreamBuilder`](crate::builders::ConverterInputStreamBuilder) which can be used to create [`ConverterInputStream`] objects.
78    pub fn builder() -> ConverterInputStreamBuilder {
79        ConverterInputStreamBuilder::new()
80    }
81}
82
83impl Default for ConverterInputStream {
84    fn default() -> Self {
85        glib::object::Object::new::<Self>()
86    }
87}
88
89// rustdoc-stripper-ignore-next
90/// A [builder-pattern] type to construct [`ConverterInputStream`] objects.
91///
92/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
93#[must_use = "The builder must be built to be used"]
94pub struct ConverterInputStreamBuilder {
95    builder: glib::object::ObjectBuilder<'static, ConverterInputStream>,
96}
97
98impl ConverterInputStreamBuilder {
99    fn new() -> Self {
100        Self {
101            builder: glib::object::Object::builder(),
102        }
103    }
104
105    /// The converter object.
106    pub fn converter(self, converter: &impl IsA<Converter>) -> Self {
107        Self {
108            builder: self
109                .builder
110                .property("converter", converter.clone().upcast()),
111        }
112    }
113
114    /// The underlying base stream on which the I/O ops will be done.
115    pub fn base_stream(self, base_stream: &impl IsA<InputStream>) -> Self {
116        Self {
117            builder: self
118                .builder
119                .property("base-stream", base_stream.clone().upcast()),
120        }
121    }
122
123    /// Whether the base stream should be closed when the filter stream is closed.
124    pub fn close_base_stream(self, close_base_stream: bool) -> Self {
125        Self {
126            builder: self
127                .builder
128                .property("close-base-stream", close_base_stream),
129        }
130    }
131
132    // rustdoc-stripper-ignore-next
133    /// Build the [`ConverterInputStream`].
134    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
135    pub fn build(self) -> ConverterInputStream {
136        self.builder.build()
137    }
138}
139
140mod sealed {
141    pub trait Sealed {}
142    impl<T: super::IsA<super::ConverterInputStream>> Sealed for T {}
143}
144
145/// Trait containing all [`struct@ConverterInputStream`] methods.
146///
147/// # Implementors
148///
149/// [`ConverterInputStream`][struct@crate::ConverterInputStream]
150pub trait ConverterInputStreamExt: IsA<ConverterInputStream> + sealed::Sealed + 'static {
151    /// Gets the #GConverter that is used by @self.
152    ///
153    /// # Returns
154    ///
155    /// the converter of the converter input stream
156    #[doc(alias = "g_converter_input_stream_get_converter")]
157    #[doc(alias = "get_converter")]
158    fn converter(&self) -> Converter {
159        unsafe {
160            from_glib_none(ffi::g_converter_input_stream_get_converter(
161                self.as_ref().to_glib_none().0,
162            ))
163        }
164    }
165}
166
167impl<O: IsA<ConverterInputStream>> ConverterInputStreamExt for O {}