gio/auto/
pollable_input_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, InputStream};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// `GPollableInputStream` is implemented by [`InputStream`][crate::InputStream]s that
10    /// can be polled for readiness to read. This can be used when
11    /// interfacing with a non-GIO API that expects
12    /// UNIX-file-descriptor-style asynchronous I/O rather than GIO-style.
13    ///
14    /// Some classes may implement `GPollableInputStream` but have only certain
15    /// instances of that class be pollable. If [`PollableInputStreamExt::can_poll()`][crate::prelude::PollableInputStreamExt::can_poll()]
16    /// returns false, then the behavior of other `GPollableInputStream` methods is
17    /// undefined.
18    ///
19    /// # Implements
20    ///
21    /// [`PollableInputStreamExt`][trait@crate::prelude::PollableInputStreamExt], [`InputStreamExt`][trait@crate::prelude::InputStreamExt], [`trait@glib::ObjectExt`], [`PollableInputStreamExtManual`][trait@crate::prelude::PollableInputStreamExtManual], [`InputStreamExtManual`][trait@crate::prelude::InputStreamExtManual]
22    #[doc(alias = "GPollableInputStream")]
23    pub struct PollableInputStream(Interface<ffi::GPollableInputStream, ffi::GPollableInputStreamInterface>) @requires InputStream;
24
25    match fn {
26        type_ => || ffi::g_pollable_input_stream_get_type(),
27    }
28}
29
30impl PollableInputStream {
31    pub const NONE: Option<&'static PollableInputStream> = None;
32}
33
34/// Trait containing all [`struct@PollableInputStream`] methods.
35///
36/// # Implementors
37///
38/// [`ConverterInputStream`][struct@crate::ConverterInputStream], [`MemoryInputStream`][struct@crate::MemoryInputStream], [`PollableInputStream`][struct@crate::PollableInputStream], [`UnixInputStream`][struct@crate::UnixInputStream]
39pub trait PollableInputStreamExt: IsA<PollableInputStream> + 'static {
40    /// Checks if @self is actually pollable. Some classes may implement
41    /// #GPollableInputStream but have only certain instances of that class
42    /// be pollable. If this method returns [`false`], then the behavior of
43    /// other #GPollableInputStream methods is undefined.
44    ///
45    /// For any given stream, the value returned by this method is constant;
46    /// a stream cannot switch from pollable to non-pollable or vice versa.
47    ///
48    /// # Returns
49    ///
50    /// [`true`] if @self is pollable, [`false`] if not.
51    #[doc(alias = "g_pollable_input_stream_can_poll")]
52    fn can_poll(&self) -> bool {
53        unsafe {
54            from_glib(ffi::g_pollable_input_stream_can_poll(
55                self.as_ref().to_glib_none().0,
56            ))
57        }
58    }
59
60    /// Checks if @self can be read.
61    ///
62    /// Note that some stream types may not be able to implement this 100%
63    /// reliably, and it is possible that a call to g_input_stream_read()
64    /// after this returns [`true`] would still block. To guarantee
65    /// non-blocking behavior, you should always use
66    /// g_pollable_input_stream_read_nonblocking(), which will return a
67    /// [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock] error rather than blocking.
68    ///
69    /// The behaviour of this method is undefined if
70    /// g_pollable_input_stream_can_poll() returns [`false`] for @self.
71    ///
72    /// # Returns
73    ///
74    /// [`true`] if @self is readable, [`false`] if not. If an error
75    ///   has occurred on @self, this will result in
76    ///   g_pollable_input_stream_is_readable() returning [`true`], and the
77    ///   next attempt to read will return the error.
78    #[doc(alias = "g_pollable_input_stream_is_readable")]
79    fn is_readable(&self) -> bool {
80        unsafe {
81            from_glib(ffi::g_pollable_input_stream_is_readable(
82                self.as_ref().to_glib_none().0,
83            ))
84        }
85    }
86}
87
88impl<O: IsA<PollableInputStream>> PollableInputStreamExt for O {}