gio/auto/
pollable_output_stream.rs1use crate::{ffi, Cancellable, OutputStream};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 #[doc(alias = "GPollableOutputStream")]
10 pub struct PollableOutputStream(Interface<ffi::GPollableOutputStream, ffi::GPollableOutputStreamInterface>) @requires OutputStream;
11
12 match fn {
13 type_ => || ffi::g_pollable_output_stream_get_type(),
14 }
15}
16
17impl PollableOutputStream {
18 pub const NONE: Option<&'static PollableOutputStream> = None;
19}
20
21pub trait PollableOutputStreamExt: IsA<PollableOutputStream> + 'static {
22 #[doc(alias = "g_pollable_output_stream_can_poll")]
23 fn can_poll(&self) -> bool {
24 unsafe {
25 from_glib(ffi::g_pollable_output_stream_can_poll(
26 self.as_ref().to_glib_none().0,
27 ))
28 }
29 }
30
31 #[doc(alias = "g_pollable_output_stream_is_writable")]
32 fn is_writable(&self) -> bool {
33 unsafe {
34 from_glib(ffi::g_pollable_output_stream_is_writable(
35 self.as_ref().to_glib_none().0,
36 ))
37 }
38 }
39
40 #[doc(alias = "g_pollable_output_stream_write_nonblocking")]
41 fn write_nonblocking(
42 &self,
43 buffer: &[u8],
44 cancellable: Option<&impl IsA<Cancellable>>,
45 ) -> Result<isize, glib::Error> {
46 let count = buffer.len() as _;
47 unsafe {
48 let mut error = std::ptr::null_mut();
49 let ret = ffi::g_pollable_output_stream_write_nonblocking(
50 self.as_ref().to_glib_none().0,
51 buffer.to_glib_none().0,
52 count,
53 cancellable.map(|p| p.as_ref()).to_glib_none().0,
54 &mut error,
55 );
56 if error.is_null() {
57 Ok(ret)
58 } else {
59 Err(from_glib_full(error))
60 }
61 }
62 }
63}
64
65impl<O: IsA<PollableOutputStream>> PollableOutputStreamExt for O {}