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