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 5 use gio_sys; 6 use glib; 7 use glib::object::IsA; 8 use glib::translate::*; 9 use glib::GString; 10 use glib_sys; 11 use gobject_sys; 12 use std::boxed::Box as Box_; 13 use std::fmt; 14 use std::pin::Pin; 15 use std::ptr; 16 use Cancellable; 17 use FileInfo; 18 use IOStream; 19 use Seekable; 20 21 glib_wrapper! { 22 pub struct FileIOStream(Object<gio_sys::GFileIOStream, gio_sys::GFileIOStreamClass, FileIOStreamClass>) @extends IOStream, @implements Seekable; 23 24 match fn { 25 get_type => || gio_sys::g_file_io_stream_get_type(), 26 } 27 } 28 29 pub const NONE_FILE_IO_STREAM: Option<&FileIOStream> = None; 30 31 pub trait FileIOStreamExt: 'static { get_etag(&self) -> Option<GString>32 fn get_etag(&self) -> Option<GString>; 33 query_info<P: IsA<Cancellable>>( &self, attributes: &str, cancellable: Option<&P>, ) -> Result<FileInfo, glib::Error>34 fn query_info<P: IsA<Cancellable>>( 35 &self, 36 attributes: &str, 37 cancellable: Option<&P>, 38 ) -> Result<FileInfo, glib::Error>; 39 query_info_async< P: IsA<Cancellable>, Q: FnOnce(Result<FileInfo, glib::Error>) + Send + 'static, >( &self, attributes: &str, io_priority: glib::Priority, cancellable: Option<&P>, callback: Q, )40 fn query_info_async< 41 P: IsA<Cancellable>, 42 Q: FnOnce(Result<FileInfo, glib::Error>) + Send + 'static, 43 >( 44 &self, 45 attributes: &str, 46 io_priority: glib::Priority, 47 cancellable: Option<&P>, 48 callback: Q, 49 ); 50 query_info_async_future( &self, attributes: &str, io_priority: glib::Priority, ) -> Pin<Box_<dyn std::future::Future<Output = Result<FileInfo, glib::Error>> + 'static>>51 fn query_info_async_future( 52 &self, 53 attributes: &str, 54 io_priority: glib::Priority, 55 ) -> Pin<Box_<dyn std::future::Future<Output = Result<FileInfo, glib::Error>> + 'static>>; 56 } 57 58 impl<O: IsA<FileIOStream>> FileIOStreamExt for O { get_etag(&self) -> Option<GString>59 fn get_etag(&self) -> Option<GString> { 60 unsafe { 61 from_glib_full(gio_sys::g_file_io_stream_get_etag( 62 self.as_ref().to_glib_none().0, 63 )) 64 } 65 } 66 query_info<P: IsA<Cancellable>>( &self, attributes: &str, cancellable: Option<&P>, ) -> Result<FileInfo, glib::Error>67 fn query_info<P: IsA<Cancellable>>( 68 &self, 69 attributes: &str, 70 cancellable: Option<&P>, 71 ) -> Result<FileInfo, glib::Error> { 72 unsafe { 73 let mut error = ptr::null_mut(); 74 let ret = gio_sys::g_file_io_stream_query_info( 75 self.as_ref().to_glib_none().0, 76 attributes.to_glib_none().0, 77 cancellable.map(|p| p.as_ref()).to_glib_none().0, 78 &mut error, 79 ); 80 if error.is_null() { 81 Ok(from_glib_full(ret)) 82 } else { 83 Err(from_glib_full(error)) 84 } 85 } 86 } 87 query_info_async< P: IsA<Cancellable>, Q: FnOnce(Result<FileInfo, glib::Error>) + Send + 'static, >( &self, attributes: &str, io_priority: glib::Priority, cancellable: Option<&P>, callback: Q, )88 fn query_info_async< 89 P: IsA<Cancellable>, 90 Q: FnOnce(Result<FileInfo, glib::Error>) + Send + 'static, 91 >( 92 &self, 93 attributes: &str, 94 io_priority: glib::Priority, 95 cancellable: Option<&P>, 96 callback: Q, 97 ) { 98 let user_data: Box_<Q> = Box_::new(callback); 99 unsafe extern "C" fn query_info_async_trampoline< 100 Q: FnOnce(Result<FileInfo, glib::Error>) + Send + 'static, 101 >( 102 _source_object: *mut gobject_sys::GObject, 103 res: *mut gio_sys::GAsyncResult, 104 user_data: glib_sys::gpointer, 105 ) { 106 let mut error = ptr::null_mut(); 107 let ret = gio_sys::g_file_io_stream_query_info_finish( 108 _source_object as *mut _, 109 res, 110 &mut error, 111 ); 112 let result = if error.is_null() { 113 Ok(from_glib_full(ret)) 114 } else { 115 Err(from_glib_full(error)) 116 }; 117 let callback: Box_<Q> = Box_::from_raw(user_data as *mut _); 118 callback(result); 119 } 120 let callback = query_info_async_trampoline::<Q>; 121 unsafe { 122 gio_sys::g_file_io_stream_query_info_async( 123 self.as_ref().to_glib_none().0, 124 attributes.to_glib_none().0, 125 io_priority.to_glib(), 126 cancellable.map(|p| p.as_ref()).to_glib_none().0, 127 Some(callback), 128 Box_::into_raw(user_data) as *mut _, 129 ); 130 } 131 } 132 query_info_async_future( &self, attributes: &str, io_priority: glib::Priority, ) -> Pin<Box_<dyn std::future::Future<Output = Result<FileInfo, glib::Error>> + 'static>>133 fn query_info_async_future( 134 &self, 135 attributes: &str, 136 io_priority: glib::Priority, 137 ) -> Pin<Box_<dyn std::future::Future<Output = Result<FileInfo, glib::Error>> + 'static>> { 138 let attributes = String::from(attributes); 139 Box_::pin(crate::GioFuture::new(self, move |obj, send| { 140 let cancellable = Cancellable::new(); 141 obj.query_info_async(&attributes, io_priority, Some(&cancellable), move |res| { 142 send.resolve(res); 143 }); 144 145 cancellable 146 })) 147 } 148 } 149 150 impl fmt::Display for FileIOStream { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result151 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 152 write!(f, "FileIOStream") 153 } 154 } 155