gdk4/
content_formats_builder.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, ContentFormats, ContentFormatsBuilder};
6
7impl ContentFormatsBuilder {
8    /// Appends all formats from @formats to @self, skipping those that
9    /// already exist.
10    /// ## `formats`
11    /// the formats to add
12    #[doc(alias = "gdk_content_formats_builder_add_formats")]
13    #[must_use]
14    pub fn add_formats(self, formats: &ContentFormats) -> Self {
15        unsafe {
16            ffi::gdk_content_formats_builder_add_formats(
17                self.to_glib_none().0,
18                formats.to_glib_none().0,
19            );
20        }
21
22        self
23    }
24
25    /// Appends @type_ to @self if it has not already been added.
26    /// ## `type_`
27    /// a `GType`
28    #[doc(alias = "gdk_content_formats_builder_add_gtype")]
29    #[must_use]
30    pub fn add_type(self, type_: glib::types::Type) -> Self {
31        unsafe {
32            ffi::gdk_content_formats_builder_add_gtype(self.to_glib_none().0, type_.into_glib());
33        }
34
35        self
36    }
37
38    /// Appends @mime_type to @self if it has not already been added.
39    /// ## `mime_type`
40    /// a mime type
41    #[doc(alias = "gdk_content_formats_builder_add_mime_type")]
42    #[must_use]
43    pub fn add_mime_type(self, mime_type: impl IntoGStr) -> Self {
44        unsafe {
45            mime_type.run_with_gstr(|mime_type| {
46                ffi::gdk_content_formats_builder_add_mime_type(
47                    self.to_glib_none().0,
48                    mime_type.as_ptr(),
49                );
50            });
51        }
52
53        self
54    }
55
56    /// Creates a new [`ContentFormats`][crate::ContentFormats] from the given @self.
57    ///
58    /// The given [`ContentFormatsBuilder`][crate::ContentFormatsBuilder] is reset once this function returns;
59    /// you cannot call this function multiple times on the same @self instance.
60    ///
61    /// This function is intended primarily for bindings. C code should use
62    /// `Gdk::ContentFormatsBuilder::free_to_formats()`.
63    ///
64    /// # Returns
65    ///
66    /// the newly created [`ContentFormats`][crate::ContentFormats]
67    ///   with all the formats added to @self
68    #[doc(alias = "gdk_content_formats_builder_to_formats")]
69    #[must_use = "The builder must be built to be used"]
70    pub fn build(self) -> ContentFormats {
71        unsafe {
72            from_glib_full(ffi::gdk_content_formats_builder_to_formats(
73                self.to_glib_none().0,
74            ))
75        }
76    }
77}