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