use crate::ffi;
use glib::{prelude::*, translate::*};
glib::wrapper! {
#[doc(alias = "MirageStream")]
pub struct Stream(Interface<ffi::MirageStream, ffi::MirageStreamInterface>);
match fn {
type_ => || ffi::mirage_stream_get_type(),
}
}
impl Stream {
pub const NONE: Option<&'static Stream> = None;
}
pub trait StreamExt: IsA<Stream> + 'static {
#[doc(alias = "mirage_stream_get_filename")]
#[doc(alias = "get_filename")]
fn filename(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::mirage_stream_get_filename(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "mirage_stream_get_g_input_stream")]
#[doc(alias = "get_g_input_stream")]
fn g_input_stream(&self) -> Option<gio::InputStream> {
unsafe {
from_glib_full(ffi::mirage_stream_get_g_input_stream(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "mirage_stream_is_writable")]
fn is_writable(&self) -> bool {
unsafe {
from_glib(ffi::mirage_stream_is_writable(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "mirage_stream_move_file")]
fn move_file(&self, new_filename: &str) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::mirage_stream_move_file(
self.as_ref().to_glib_none().0,
new_filename.to_glib_none().0,
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "mirage_stream_seek")]
fn seek(&self, offset: i64, type_: glib::SeekType) -> Result<(), glib::Error> {
unsafe {
let mut error = std::ptr::null_mut();
let is_ok = ffi::mirage_stream_seek(
self.as_ref().to_glib_none().0,
offset,
type_.into_glib(),
&mut error,
);
debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
}
}
}
#[doc(alias = "mirage_stream_tell")]
fn tell(&self) -> i64 {
unsafe { ffi::mirage_stream_tell(self.as_ref().to_glib_none().0) }
}
}
impl<O: IsA<Stream>> StreamExt for O {}