soup/auto/
multipart_input_stream.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files)
4// DO NOT EDIT
5
6use crate::{ffi, Message, MessageHeaders};
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10    #[doc(alias = "SoupMultipartInputStream")]
11    pub struct MultipartInputStream(Object<ffi::SoupMultipartInputStream, ffi::SoupMultipartInputStreamClass>) @extends gio::FilterInputStream, gio::InputStream, @implements gio::PollableInputStream;
12
13    match fn {
14        type_ => || ffi::soup_multipart_input_stream_get_type(),
15    }
16}
17
18impl MultipartInputStream {
19    #[doc(alias = "soup_multipart_input_stream_new")]
20    pub fn new(msg: &Message, base_stream: &impl IsA<gio::InputStream>) -> MultipartInputStream {
21        skip_assert_initialized!();
22        unsafe {
23            from_glib_full(ffi::soup_multipart_input_stream_new(
24                msg.to_glib_none().0,
25                base_stream.as_ref().to_glib_none().0,
26            ))
27        }
28    }
29
30    // rustdoc-stripper-ignore-next
31    /// Creates a new builder-pattern struct instance to construct [`MultipartInputStream`] objects.
32    ///
33    /// This method returns an instance of [`MultipartInputStreamBuilder`](crate::builders::MultipartInputStreamBuilder) which can be used to create [`MultipartInputStream`] objects.
34    pub fn builder() -> MultipartInputStreamBuilder {
35        MultipartInputStreamBuilder::new()
36    }
37
38    #[doc(alias = "soup_multipart_input_stream_get_headers")]
39    #[doc(alias = "get_headers")]
40    pub fn headers(&self) -> Option<MessageHeaders> {
41        unsafe {
42            from_glib_none(ffi::soup_multipart_input_stream_get_headers(
43                self.to_glib_none().0,
44            ))
45        }
46    }
47
48    #[doc(alias = "soup_multipart_input_stream_next_part")]
49    pub fn next_part(
50        &self,
51        cancellable: Option<&impl IsA<gio::Cancellable>>,
52    ) -> Result<Option<gio::InputStream>, glib::Error> {
53        unsafe {
54            let mut error = std::ptr::null_mut();
55            let ret = ffi::soup_multipart_input_stream_next_part(
56                self.to_glib_none().0,
57                cancellable.map(|p| p.as_ref()).to_glib_none().0,
58                &mut error,
59            );
60            if error.is_null() {
61                Ok(from_glib_full(ret))
62            } else {
63                Err(from_glib_full(error))
64            }
65        }
66    }
67
68    pub fn message(&self) -> Option<Message> {
69        ObjectExt::property(self, "message")
70    }
71}
72
73impl Default for MultipartInputStream {
74    fn default() -> Self {
75        glib::object::Object::new::<Self>()
76    }
77}
78
79// rustdoc-stripper-ignore-next
80/// A [builder-pattern] type to construct [`MultipartInputStream`] objects.
81///
82/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
83#[must_use = "The builder must be built to be used"]
84pub struct MultipartInputStreamBuilder {
85    builder: glib::object::ObjectBuilder<'static, MultipartInputStream>,
86}
87
88impl MultipartInputStreamBuilder {
89    fn new() -> Self {
90        Self {
91            builder: glib::object::Object::builder(),
92        }
93    }
94
95    pub fn message(self, message: &Message) -> Self {
96        Self {
97            builder: self.builder.property("message", message.clone()),
98        }
99    }
100
101    pub fn base_stream(self, base_stream: &impl IsA<gio::InputStream>) -> Self {
102        Self {
103            builder: self
104                .builder
105                .property("base-stream", base_stream.clone().upcast()),
106        }
107    }
108
109    pub fn close_base_stream(self, close_base_stream: bool) -> Self {
110        Self {
111            builder: self
112                .builder
113                .property("close-base-stream", close_base_stream),
114        }
115    }
116
117    // rustdoc-stripper-ignore-next
118    /// Build the [`MultipartInputStream`].
119    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
120    pub fn build(self) -> MultipartInputStream {
121        self.builder.build()
122    }
123}