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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// This file was generated by gir (https://github.com/gtk-rs/gir @ fe7a6ff+)
// from gir-files (https://github.com/gtk-rs/gir-files @ b215ee8)
// DO NOT EDIT

use Object;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// A MIME part iterator.
    pub struct PartIter(Boxed<ffi::GMimePartIter>);

    match fn {
        copy => |ptr| gobject_ffi::g_boxed_copy(ffi::g_mime_part_iter_get_type(), ptr as *mut _) as *mut ffi::GMimePartIter,
        free => |ptr| gobject_ffi::g_boxed_free(ffi::g_mime_part_iter_get_type(), ptr as *mut _),
        get_type => || ffi::g_mime_part_iter_get_type(),
    }
}

impl PartIter {
    /// Creates a new `PartIter` for iterating over `toplevel`'s subparts.
    /// ## `toplevel`
    /// a `Object` to use as the toplevel
    ///
    /// # Returns
    ///
    /// a newly allocated `PartIter` which should be freed
    /// using `PartIter::free` when finished with it.
    pub fn new<P: IsA<Object>>(toplevel: &P) -> PartIter {
        unsafe {
            from_glib_full(ffi::g_mime_part_iter_new(toplevel.to_glib_none().0))
        }
    }

    /// Clones the `self`, including its current state.
    ///
    /// # Returns
    ///
    /// a new `PartIter` that is identical to `self`.
    pub fn clone(&mut self) -> Option<PartIter> {
        unsafe {
            from_glib_full(ffi::g_mime_part_iter_clone(self.to_glib_none_mut().0))
        }
    }

    /// Gets the `Object` at the current `PartIter` position.
    ///
    /// # Returns
    ///
    /// the current `Object` or `None` if the
    /// state of `self` is invalid.
    pub fn get_current(&mut self) -> Option<Object> {
        unsafe {
            from_glib_none(ffi::g_mime_part_iter_get_current(self.to_glib_none_mut().0))
        }
    }

    /// Gets the parent of the `Object` at the current `PartIter`
    /// position.
    ///
    /// # Returns
    ///
    /// the parent `Object` or `None` if the
    /// state of `self` is invalid.
    pub fn get_parent(&mut self) -> Option<Object> {
        unsafe {
            from_glib_none(ffi::g_mime_part_iter_get_parent(self.to_glib_none_mut().0))
        }
    }

    /// Gets the path of the current `Object` in the MIME structure
    /// used to initialize `self`.
    ///
    /// # Returns
    ///
    /// a newly allocated string representation of the path to the
    /// `Object` at the current `PartIter` position.
    pub fn get_path(&mut self) -> Option<String> {
        unsafe {
            from_glib_full(ffi::g_mime_part_iter_get_path(self.to_glib_none_mut().0))
        }
    }

    /// Gets the toplevel `Object` used to initialize `self`.
    ///
    /// # Returns
    ///
    /// the toplevel `Object`.
    pub fn get_toplevel(&mut self) -> Option<Object> {
        unsafe {
            from_glib_none(ffi::g_mime_part_iter_get_toplevel(self.to_glib_none_mut().0))
        }
    }

    /// Checks that the current state of `self` is valid.
    ///
    /// # Returns
    ///
    /// `true` if `self` is valid or `false` otherwise.
    pub fn is_valid(&mut self) -> bool {
        unsafe {
            from_glib(ffi::g_mime_part_iter_is_valid(self.to_glib_none_mut().0))
        }
    }

    /// Updates the state of `self` to point to the `Object` specified
    /// by `path`.
    /// ## `path`
    /// a string representing the path to jump to
    ///
    /// # Returns
    ///
    /// `true` if the `Object` specified by `path` exists or
    /// `false` otherwise.
    pub fn jump_to(&mut self, path: &str) -> bool {
        unsafe {
            from_glib(ffi::g_mime_part_iter_jump_to(self.to_glib_none_mut().0, path.to_glib_none().0))
        }
    }

    /// Advances to the next part in the MIME structure used to initialize
    /// `self`.
    ///
    /// # Returns
    ///
    /// `true` if successful or `false` otherwise.
    pub fn next(&mut self) -> bool {
        unsafe {
            from_glib(ffi::g_mime_part_iter_next(self.to_glib_none_mut().0))
        }
    }

    /// Rewinds to the previous part in the MIME structure used to
    /// initialize `self`.
    ///
    /// # Returns
    ///
    /// `true` if successful or `false` otherwise.
    pub fn prev(&mut self) -> bool {
        unsafe {
            from_glib(ffi::g_mime_part_iter_prev(self.to_glib_none_mut().0))
        }
    }

    /// Removes the `Object` at the current position from its
    /// parent. If successful, `self` is advanced to the next position
    /// (since the current position will become invalid).
    ///
    /// # Returns
    ///
    /// `true` if the part at the current position was removed or
    /// `false` otherwise.
    pub fn remove(&mut self) -> bool {
        unsafe {
            from_glib(ffi::g_mime_part_iter_remove(self.to_glib_none_mut().0))
        }
    }

    /// Replaces the `Object` at the current position with `replacement`.
    /// ## `replacement`
    /// a `Object`
    ///
    /// # Returns
    ///
    /// `true` if the part at the current position was replaced or
    /// `false` otherwise.
    pub fn replace<P: IsA<Object>>(&mut self, replacement: &P) -> bool {
        unsafe {
            from_glib(ffi::g_mime_part_iter_replace(self.to_glib_none_mut().0, replacement.to_glib_none().0))
        }
    }

    /// Resets the state of `self` to its initial state.
    pub fn reset(&mut self) {
        unsafe {
            ffi::g_mime_part_iter_reset(self.to_glib_none_mut().0);
        }
    }
}