gdk4/
content_formats_builder.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;

use crate::{ffi, ContentFormats, ContentFormatsBuilder};

impl ContentFormatsBuilder {
    /// Appends all formats from @formats to @self, skipping those that
    /// already exist.
    /// ## `formats`
    /// the formats to add
    #[doc(alias = "gdk_content_formats_builder_add_formats")]
    #[must_use]
    pub fn add_formats(self, formats: &ContentFormats) -> Self {
        unsafe {
            ffi::gdk_content_formats_builder_add_formats(
                self.to_glib_none().0,
                formats.to_glib_none().0,
            );
        }

        self
    }

    /// Appends @type_ to @self if it has not already been added.
    /// ## `type_`
    /// a `GType`
    #[doc(alias = "gdk_content_formats_builder_add_gtype")]
    #[must_use]
    pub fn add_type(self, type_: glib::types::Type) -> Self {
        unsafe {
            ffi::gdk_content_formats_builder_add_gtype(self.to_glib_none().0, type_.into_glib());
        }

        self
    }

    /// Appends @mime_type to @self if it has not already been added.
    /// ## `mime_type`
    /// a mime type
    #[doc(alias = "gdk_content_formats_builder_add_mime_type")]
    #[must_use]
    pub fn add_mime_type(self, mime_type: impl IntoGStr) -> Self {
        unsafe {
            mime_type.run_with_gstr(|mime_type| {
                ffi::gdk_content_formats_builder_add_mime_type(
                    self.to_glib_none().0,
                    mime_type.as_ptr(),
                );
            });
        }

        self
    }

    /// Creates a new [`ContentFormats`][crate::ContentFormats] from the given @self.
    ///
    /// The given [`ContentFormatsBuilder`][crate::ContentFormatsBuilder] is reset once this function returns;
    /// you cannot call this function multiple times on the same @self instance.
    ///
    /// This function is intended primarily for bindings. C code should use
    /// `Gdk::ContentFormatsBuilder::free_to_formats()`.
    ///
    /// # Returns
    ///
    /// the newly created [`ContentFormats`][crate::ContentFormats]
    ///   with all the formats added to @self
    #[doc(alias = "gdk_content_formats_builder_to_formats")]
    #[must_use = "The builder must be built to be used"]
    pub fn build(self) -> ContentFormats {
        unsafe {
            from_glib_full(ffi::gdk_content_formats_builder_to_formats(
                self.to_glib_none().0,
            ))
        }
    }
}