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 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
21mod sealed {
22    pub trait Sealed {}
23    impl<T: super::IsA<super::PollableOutputStream>> Sealed for T {}
24}
25
26pub trait PollableOutputStreamExt: IsA<PollableOutputStream> + sealed::Sealed + 'static {
27    #[doc(alias = "g_pollable_output_stream_can_poll")]
28    fn can_poll(&self) -> bool {
29        unsafe {
30            from_glib(ffi::g_pollable_output_stream_can_poll(
31                self.as_ref().to_glib_none().0,
32            ))
33        }
34    }
35
36    #[doc(alias = "g_pollable_output_stream_is_writable")]
37    fn is_writable(&self) -> bool {
38        unsafe {
39            from_glib(ffi::g_pollable_output_stream_is_writable(
40                self.as_ref().to_glib_none().0,
41            ))
42        }
43    }
44
45    #[doc(alias = "g_pollable_output_stream_write_nonblocking")]
46    fn write_nonblocking(
47        &self,
48        buffer: &[u8],
49        cancellable: Option<&impl IsA<Cancellable>>,
50    ) -> Result<isize, glib::Error> {
51        let count = buffer.len() as _;
52        unsafe {
53            let mut error = std::ptr::null_mut();
54            let ret = ffi::g_pollable_output_stream_write_nonblocking(
55                self.as_ref().to_glib_none().0,
56                buffer.to_glib_none().0,
57                count,
58                cancellable.map(|p| p.as_ref()).to_glib_none().0,
59                &mut error,
60            );
61            if error.is_null() {
62                Ok(ret)
63            } else {
64                Err(from_glib_full(error))
65            }
66        }
67    }
68}
69
70impl<O: IsA<PollableOutputStream>> PollableOutputStreamExt for O {}