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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// 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 SeekWhence;
use ffi;
use glib::object::IsA;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::mem;
use std::ptr;

glib_wrapper! {
    /// Abstract I/O stream class.
    ///
    /// # Implements
    ///
    /// [`StreamExt`](trait.StreamExt.html)
    pub struct Stream(Object<ffi::GMimeStream, ffi::GMimeStreamClass>);

    match fn {
        get_type => || ffi::g_mime_stream_get_type(),
    }
}

/// Trait containing all `Stream` methods.
///
/// # Implementors
///
/// [`StreamBuffer`](struct.StreamBuffer.html), [`StreamCat`](struct.StreamCat.html), [`StreamFile`](struct.StreamFile.html), [`StreamFilter`](struct.StreamFilter.html), [`StreamFs`](struct.StreamFs.html), [`StreamGIO`](struct.StreamGIO.html), [`StreamMem`](struct.StreamMem.html), [`StreamMmap`](struct.StreamMmap.html), [`StreamNull`](struct.StreamNull.html), [`StreamPipe`](struct.StreamPipe.html), [`Stream`](struct.Stream.html)
pub trait StreamExt {
    /// Reads in at most one less than `max` characters from `self` and
    /// stores them into the buffer pointed to by `buf`. Reading stops after
    /// an EOS or newline ('\n'). If a newline is read, it is stored into
    /// the buffer. A '\0' is stored after the last character in the
    /// buffer.
    /// ## `buf`
    /// line buffer
    /// ## `max`
    /// max length of a line
    ///
    /// # Returns
    ///
    /// the number of characters read into `buf` on success or %-1
    /// on fail.
    fn buffer_gets(&self, buf: &str, max: usize) -> isize;

    //fn buffer_readln(&self, buffer: /*Ignored*/&glib::ByteArray);

    /// Closes the stream.
    ///
    /// # Returns
    ///
    /// `0` on success or %-1 on fail.
    fn close(&self) -> i32;

    /// Initializes a new stream with bounds `start` and `end`.
    /// ## `start`
    /// start boundary
    /// ## `end`
    /// end boundary
    fn construct(&self, start: i64, end: i64);

    /// Tests the end-of-stream indicator for `self`.
    ///
    /// # Returns
    ///
    /// `true` on EOS or `false` otherwise.
    fn eos(&self) -> bool;

    /// Sync's the stream to disk.
    ///
    /// # Returns
    ///
    /// `0` on success or %-1 on fail.
    fn flush(&self) -> i32;

    /// Gets the length of the stream.
    ///
    /// # Returns
    ///
    /// the length of the stream or %-1 if unknown.
    fn length(&self) -> i64;

    //fn printf(&self, fmt: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> isize;

    /// Attempts to read up to `len` bytes from `self` into `buf`.
    /// ## `buf`
    /// buffer
    /// ## `len`
    /// buffer length
    ///
    /// # Returns
    ///
    /// the number of bytes read or %-1 on fail.
    fn read(&self, buf: &[u8]) -> isize;

    /// Resets the stream.
    ///
    /// # Returns
    ///
    /// `0` on success or %-1 on fail.
    fn reset(&self) -> i32;

    /// Repositions the offset of the stream `self` to
    /// the argument `offset` according to the
    /// directive `whence` as follows:
    ///
    ///  `SeekWhence::Set`: Seek `offset` bytes relative to
    ///  the beginning (bound_start) of the stream.
    ///
    ///  `SeekWhence::Cur`: Seek `offset` bytes relative to the
    ///  current offset of the stream.
    ///
    ///  `SeekWhence::End`: Seek `offset` bytes relative to the
    ///  end of the stream (bound_end if non-negative).
    /// ## `offset`
    /// positional offset
    /// ## `whence`
    /// seek directive
    ///
    /// # Returns
    ///
    /// the resultant position on success or %-1 on fail.
    fn seek(&self, offset: i64, whence: SeekWhence) -> i64;

    /// Set the bounds on a stream.
    /// ## `start`
    /// start boundary
    /// ## `end`
    /// end boundary
    fn set_bounds(&self, start: i64, end: i64);

    /// Creates a new substream of `self` with bounds `start` and `end`.
    /// ## `start`
    /// start boundary
    /// ## `end`
    /// end boundary
    ///
    /// # Returns
    ///
    /// a substream of `self` with bounds `start`
    /// and `end`.
    fn substream(&self, start: i64, end: i64) -> Option<Stream>;

    /// Gets the current offset within the stream.
    ///
    /// # Returns
    ///
    /// the current position within the stream or %-1 on fail.
    fn tell(&self) -> i64;

    /// Attempts to write up to `len` bytes of `buf` to `self`.
    /// ## `buf`
    /// buffer
    /// ## `len`
    /// buffer length
    ///
    /// # Returns
    ///
    /// the number of bytes written or %-1 on fail.
    fn write(&self, buf: &str) -> isize;

    /// Writes `string` to `self`.
    /// ## `str`
    /// string to write
    ///
    /// # Returns
    ///
    /// the number of bytes written or %-1 on fail.
    fn write_string(&self, str: &str) -> isize;

    /// Attempts to write the source stream to the destination stream.
    /// ## `dest`
    /// destination stream
    ///
    /// # Returns
    ///
    /// the number of bytes written or %-1 on fail.
    fn write_to_stream<P: IsA<Stream>>(&self, dest: &P) -> i64;

    //fn writev(&self, vector: /*Ignored*/&mut StreamIOVector, count: usize) -> i64;
}

impl<O: IsA<Stream>> StreamExt for O {
    fn buffer_gets(&self, buf: &str, max: usize) -> isize {
        unsafe {
            ffi::g_mime_stream_buffer_gets(self.to_glib_none().0, buf.to_glib_none().0, max)
        }
    }

    //fn buffer_readln(&self, buffer: /*Ignored*/&glib::ByteArray) {
    //    unsafe { TODO: call ffi::g_mime_stream_buffer_readln() }
    //}

    fn close(&self) -> i32 {
        unsafe {
            ffi::g_mime_stream_close(self.to_glib_none().0)
        }
    }

    fn construct(&self, start: i64, end: i64) {
        unsafe {
            ffi::g_mime_stream_construct(self.to_glib_none().0, start, end);
        }
    }

    fn eos(&self) -> bool {
        unsafe {
            from_glib(ffi::g_mime_stream_eos(self.to_glib_none().0))
        }
    }

    fn flush(&self) -> i32 {
        unsafe {
            ffi::g_mime_stream_flush(self.to_glib_none().0)
        }
    }

    fn length(&self) -> i64 {
        unsafe {
            ffi::g_mime_stream_length(self.to_glib_none().0)
        }
    }

    //fn printf(&self, fmt: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) -> isize {
    //    unsafe { TODO: call ffi::g_mime_stream_printf() }
    //}

    fn read(&self, buf: &[u8]) -> isize {
        let len = buf.len() as usize;
        unsafe {
            ffi::g_mime_stream_read(self.to_glib_none().0, buf.to_glib_none().0, len)
        }
    }

    fn reset(&self) -> i32 {
        unsafe {
            ffi::g_mime_stream_reset(self.to_glib_none().0)
        }
    }

    fn seek(&self, offset: i64, whence: SeekWhence) -> i64 {
        unsafe {
            ffi::g_mime_stream_seek(self.to_glib_none().0, offset, whence.to_glib())
        }
    }

    fn set_bounds(&self, start: i64, end: i64) {
        unsafe {
            ffi::g_mime_stream_set_bounds(self.to_glib_none().0, start, end);
        }
    }

    fn substream(&self, start: i64, end: i64) -> Option<Stream> {
        unsafe {
            from_glib_full(ffi::g_mime_stream_substream(self.to_glib_none().0, start, end))
        }
    }

    fn tell(&self) -> i64 {
        unsafe {
            ffi::g_mime_stream_tell(self.to_glib_none().0)
        }
    }

    fn write(&self, buf: &str) -> isize {
        let len = buf.len() as usize;
        unsafe {
            ffi::g_mime_stream_write(self.to_glib_none().0, buf.to_glib_none().0, len)
        }
    }

    fn write_string(&self, str: &str) -> isize {
        unsafe {
            ffi::g_mime_stream_write_string(self.to_glib_none().0, str.to_glib_none().0)
        }
    }

    fn write_to_stream<P: IsA<Stream>>(&self, dest: &P) -> i64 {
        unsafe {
            ffi::g_mime_stream_write_to_stream(self.to_glib_none().0, dest.to_glib_none().0)
        }
    }

    //fn writev(&self, vector: /*Ignored*/&mut StreamIOVector, count: usize) -> i64 {
    //    unsafe { TODO: call ffi::g_mime_stream_writev() }
    //}
}