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
34mod sealed {
35    pub trait Sealed {}
36    impl<T: super::IsA<super::PollableInputStream>> Sealed for T {}
37}
38
39/// Trait containing all [`struct@PollableInputStream`] methods.
40///
41/// # Implementors
42///
43/// [`ConverterInputStream`][struct@crate::ConverterInputStream], [`MemoryInputStream`][struct@crate::MemoryInputStream], [`PollableInputStream`][struct@crate::PollableInputStream], [`UnixInputStream`][struct@crate::UnixInputStream]
44pub trait PollableInputStreamExt: IsA<PollableInputStream> + sealed::Sealed + 'static {
45    /// Checks if @self is actually pollable. Some classes may implement
46    /// #GPollableInputStream but have only certain instances of that class
47    /// be pollable. If this method returns [`false`], then the behavior of
48    /// other #GPollableInputStream methods is undefined.
49    ///
50    /// For any given stream, the value returned by this method is constant;
51    /// a stream cannot switch from pollable to non-pollable or vice versa.
52    ///
53    /// # Returns
54    ///
55    /// [`true`] if @self is pollable, [`false`] if not.
56    #[doc(alias = "g_pollable_input_stream_can_poll")]
57    fn can_poll(&self) -> bool {
58        unsafe {
59            from_glib(ffi::g_pollable_input_stream_can_poll(
60                self.as_ref().to_glib_none().0,
61            ))
62        }
63    }
64
65    /// Checks if @self can be read.
66    ///
67    /// Note that some stream types may not be able to implement this 100%
68    /// reliably, and it is possible that a call to g_input_stream_read()
69    /// after this returns [`true`] would still block. To guarantee
70    /// non-blocking behavior, you should always use
71    /// g_pollable_input_stream_read_nonblocking(), which will return a
72    /// [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock] error rather than blocking.
73    ///
74    /// The behaviour of this method is undefined if
75    /// g_pollable_input_stream_can_poll() returns [`false`] for @self.
76    ///
77    /// # Returns
78    ///
79    /// [`true`] if @self is readable, [`false`] if not. If an error
80    ///   has occurred on @self, this will result in
81    ///   g_pollable_input_stream_is_readable() returning [`true`], and the
82    ///   next attempt to read will return the error.
83    #[doc(alias = "g_pollable_input_stream_is_readable")]
84    fn is_readable(&self) -> bool {
85        unsafe {
86            from_glib(ffi::g_pollable_input_stream_is_readable(
87                self.as_ref().to_glib_none().0,
88            ))
89        }
90    }
91}
92
93impl<O: IsA<PollableInputStream>> PollableInputStreamExt for O {}