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
// 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::InputStream;
use glib::object::IsA;
use glib::translate::*;
use std::fmt;
glib::wrapper! {
/// [`PollableInputStream`][crate::PollableInputStream] is implemented by `GInputStreams` 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.
///
/// # 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;
}
/// 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: 'static {
/// Checks if `self` is actually pollable. Some classes may implement
/// [`PollableInputStream`][crate::PollableInputStream] but have only certain instances of that class
/// be pollable. If this method returns [`false`], then the behavior of
/// other [`PollableInputStream`][crate::PollableInputStream] 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;
/// 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 [`InputStreamExtManual::read()`][crate::prelude::InputStreamExtManual::read()]
/// after this returns [`true`] would still block. To guarantee
/// non-blocking behavior, you should always use
/// [`PollableInputStreamExtManual::read_nonblocking()`][crate::prelude::PollableInputStreamExtManual::read_nonblocking()], which will return a
/// [`IOErrorEnum::WouldBlock`][crate::IOErrorEnum::WouldBlock] error rather than blocking.
///
/// # Returns
///
/// [`true`] if `self` is readable, [`false`] if not. If an error
/// has occurred on `self`, this will result in
/// [`is_readable()`][Self::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;
}
impl<O: IsA<PollableInputStream>> PollableInputStreamExt for O {
fn can_poll(&self) -> bool {
unsafe {
from_glib(ffi::g_pollable_input_stream_can_poll(
self.as_ref().to_glib_none().0,
))
}
}
fn is_readable(&self) -> bool {
unsafe {
from_glib(ffi::g_pollable_input_stream_is_readable(
self.as_ref().to_glib_none().0,
))
}
}
}
impl fmt::Display for PollableInputStream {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str("PollableInputStream")
}
}