gio/auto/
pollable_output_stream.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use gio_sys;
6use glib::object::IsA;
7use glib::translate::*;
8use std::fmt;
9use std::ptr;
10use Cancellable;
11use Error;
12use OutputStream;
13
14glib_wrapper! {
15    pub struct PollableOutputStream(Interface<gio_sys::GPollableOutputStream>) @requires OutputStream;
16
17    match fn {
18        get_type => || gio_sys::g_pollable_output_stream_get_type(),
19    }
20}
21
22pub const NONE_POLLABLE_OUTPUT_STREAM: Option<&PollableOutputStream> = None;
23
24pub trait PollableOutputStreamExt: 'static {
25    fn can_poll(&self) -> bool;
26
27    fn is_writable(&self) -> bool;
28
29    fn write_nonblocking<P: IsA<Cancellable>>(
30        &self,
31        buffer: &[u8],
32        cancellable: Option<&P>,
33    ) -> Result<isize, Error>;
34}
35
36impl<O: IsA<PollableOutputStream>> PollableOutputStreamExt for O {
37    fn can_poll(&self) -> bool {
38        unsafe {
39            from_glib(gio_sys::g_pollable_output_stream_can_poll(
40                self.as_ref().to_glib_none().0,
41            ))
42        }
43    }
44
45    fn is_writable(&self) -> bool {
46        unsafe {
47            from_glib(gio_sys::g_pollable_output_stream_is_writable(
48                self.as_ref().to_glib_none().0,
49            ))
50        }
51    }
52
53    fn write_nonblocking<P: IsA<Cancellable>>(
54        &self,
55        buffer: &[u8],
56        cancellable: Option<&P>,
57    ) -> Result<isize, Error> {
58        let count = buffer.len() as usize;
59        unsafe {
60            let mut error = ptr::null_mut();
61            let ret = gio_sys::g_pollable_output_stream_write_nonblocking(
62                self.as_ref().to_glib_none().0,
63                buffer.to_glib_none().0,
64                count,
65                cancellable.map(|p| p.as_ref()).to_glib_none().0,
66                &mut error,
67            );
68            if error.is_null() {
69                Ok(ret)
70            } else {
71                Err(from_glib_full(error))
72            }
73        }
74    }
75}
76
77impl fmt::Display for PollableOutputStream {
78    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
79        write!(f, "PollableOutputStream")
80    }
81}