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 crate::Cancellable; 6 use crate::DataStreamByteOrder; 7 use crate::FilterOutputStream; 8 use crate::OutputStream; 9 use crate::Seekable; 10 use glib::object::Cast; 11 use glib::object::IsA; 12 use glib::signal::connect_raw; 13 use glib::signal::SignalHandlerId; 14 use glib::translate::*; 15 use glib::StaticType; 16 use glib::ToValue; 17 use std::boxed::Box as Box_; 18 use std::fmt; 19 use std::mem::transmute; 20 use std::ptr; 21 22 glib::wrapper! { 23 #[doc(alias = "GDataOutputStream")] 24 pub struct DataOutputStream(Object<ffi::GDataOutputStream, ffi::GDataOutputStreamClass>) @extends FilterOutputStream, OutputStream, @implements Seekable; 25 26 match fn { 27 type_ => || ffi::g_data_output_stream_get_type(), 28 } 29 } 30 31 impl DataOutputStream { 32 #[doc(alias = "g_data_output_stream_new")] new<P: IsA<OutputStream>>(base_stream: &P) -> DataOutputStream33 pub fn new<P: IsA<OutputStream>>(base_stream: &P) -> DataOutputStream { 34 unsafe { 35 from_glib_full(ffi::g_data_output_stream_new( 36 base_stream.as_ref().to_glib_none().0, 37 )) 38 } 39 } 40 41 // rustdoc-stripper-ignore-next 42 /// Creates a new builder-pattern struct instance to construct [`DataOutputStream`] objects. 43 /// 44 /// This method returns an instance of [`DataOutputStreamBuilder`] which can be used to create [`DataOutputStream`] objects. builder() -> DataOutputStreamBuilder45 pub fn builder() -> DataOutputStreamBuilder { 46 DataOutputStreamBuilder::default() 47 } 48 } 49 50 #[derive(Clone, Default)] 51 // rustdoc-stripper-ignore-next 52 /// A [builder-pattern] type to construct [`DataOutputStream`] objects. 53 /// 54 /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html 55 pub struct DataOutputStreamBuilder { 56 byte_order: Option<DataStreamByteOrder>, 57 base_stream: Option<OutputStream>, 58 close_base_stream: Option<bool>, 59 } 60 61 impl DataOutputStreamBuilder { 62 // rustdoc-stripper-ignore-next 63 /// Create a new [`DataOutputStreamBuilder`]. new() -> Self64 pub fn new() -> Self { 65 Self::default() 66 } 67 68 // rustdoc-stripper-ignore-next 69 /// Build the [`DataOutputStream`]. build(self) -> DataOutputStream70 pub fn build(self) -> DataOutputStream { 71 let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 72 if let Some(ref byte_order) = self.byte_order { 73 properties.push(("byte-order", byte_order)); 74 } 75 if let Some(ref base_stream) = self.base_stream { 76 properties.push(("base-stream", base_stream)); 77 } 78 if let Some(ref close_base_stream) = self.close_base_stream { 79 properties.push(("close-base-stream", close_base_stream)); 80 } 81 glib::Object::new::<DataOutputStream>(&properties) 82 .expect("Failed to create an instance of DataOutputStream") 83 } 84 byte_order(mut self, byte_order: DataStreamByteOrder) -> Self85 pub fn byte_order(mut self, byte_order: DataStreamByteOrder) -> Self { 86 self.byte_order = Some(byte_order); 87 self 88 } 89 base_stream<P: IsA<OutputStream>>(mut self, base_stream: &P) -> Self90 pub fn base_stream<P: IsA<OutputStream>>(mut self, base_stream: &P) -> Self { 91 self.base_stream = Some(base_stream.clone().upcast()); 92 self 93 } 94 close_base_stream(mut self, close_base_stream: bool) -> Self95 pub fn close_base_stream(mut self, close_base_stream: bool) -> Self { 96 self.close_base_stream = Some(close_base_stream); 97 self 98 } 99 } 100 101 pub const NONE_DATA_OUTPUT_STREAM: Option<&DataOutputStream> = None; 102 103 pub trait DataOutputStreamExt: 'static { 104 #[doc(alias = "g_data_output_stream_get_byte_order")] 105 #[doc(alias = "get_byte_order")] byte_order(&self) -> DataStreamByteOrder106 fn byte_order(&self) -> DataStreamByteOrder; 107 108 #[doc(alias = "g_data_output_stream_put_byte")] put_byte<P: IsA<Cancellable>>( &self, data: u8, cancellable: Option<&P>, ) -> Result<(), glib::Error>109 fn put_byte<P: IsA<Cancellable>>( 110 &self, 111 data: u8, 112 cancellable: Option<&P>, 113 ) -> Result<(), glib::Error>; 114 115 #[doc(alias = "g_data_output_stream_put_int16")] put_int16<P: IsA<Cancellable>>( &self, data: i16, cancellable: Option<&P>, ) -> Result<(), glib::Error>116 fn put_int16<P: IsA<Cancellable>>( 117 &self, 118 data: i16, 119 cancellable: Option<&P>, 120 ) -> Result<(), glib::Error>; 121 122 #[doc(alias = "g_data_output_stream_put_int32")] put_int32<P: IsA<Cancellable>>( &self, data: i32, cancellable: Option<&P>, ) -> Result<(), glib::Error>123 fn put_int32<P: IsA<Cancellable>>( 124 &self, 125 data: i32, 126 cancellable: Option<&P>, 127 ) -> Result<(), glib::Error>; 128 129 #[doc(alias = "g_data_output_stream_put_int64")] put_int64<P: IsA<Cancellable>>( &self, data: i64, cancellable: Option<&P>, ) -> Result<(), glib::Error>130 fn put_int64<P: IsA<Cancellable>>( 131 &self, 132 data: i64, 133 cancellable: Option<&P>, 134 ) -> Result<(), glib::Error>; 135 136 #[doc(alias = "g_data_output_stream_put_string")] put_string<P: IsA<Cancellable>>( &self, str: &str, cancellable: Option<&P>, ) -> Result<(), glib::Error>137 fn put_string<P: IsA<Cancellable>>( 138 &self, 139 str: &str, 140 cancellable: Option<&P>, 141 ) -> Result<(), glib::Error>; 142 143 #[doc(alias = "g_data_output_stream_put_uint16")] put_uint16<P: IsA<Cancellable>>( &self, data: u16, cancellable: Option<&P>, ) -> Result<(), glib::Error>144 fn put_uint16<P: IsA<Cancellable>>( 145 &self, 146 data: u16, 147 cancellable: Option<&P>, 148 ) -> Result<(), glib::Error>; 149 150 #[doc(alias = "g_data_output_stream_put_uint32")] put_uint32<P: IsA<Cancellable>>( &self, data: u32, cancellable: Option<&P>, ) -> Result<(), glib::Error>151 fn put_uint32<P: IsA<Cancellable>>( 152 &self, 153 data: u32, 154 cancellable: Option<&P>, 155 ) -> Result<(), glib::Error>; 156 157 #[doc(alias = "g_data_output_stream_put_uint64")] put_uint64<P: IsA<Cancellable>>( &self, data: u64, cancellable: Option<&P>, ) -> Result<(), glib::Error>158 fn put_uint64<P: IsA<Cancellable>>( 159 &self, 160 data: u64, 161 cancellable: Option<&P>, 162 ) -> Result<(), glib::Error>; 163 164 #[doc(alias = "g_data_output_stream_set_byte_order")] set_byte_order(&self, order: DataStreamByteOrder)165 fn set_byte_order(&self, order: DataStreamByteOrder); 166 167 #[doc(alias = "byte-order")] connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId168 fn connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; 169 } 170 171 impl<O: IsA<DataOutputStream>> DataOutputStreamExt for O { byte_order(&self) -> DataStreamByteOrder172 fn byte_order(&self) -> DataStreamByteOrder { 173 unsafe { 174 from_glib(ffi::g_data_output_stream_get_byte_order( 175 self.as_ref().to_glib_none().0, 176 )) 177 } 178 } 179 put_byte<P: IsA<Cancellable>>( &self, data: u8, cancellable: Option<&P>, ) -> Result<(), glib::Error>180 fn put_byte<P: IsA<Cancellable>>( 181 &self, 182 data: u8, 183 cancellable: Option<&P>, 184 ) -> Result<(), glib::Error> { 185 unsafe { 186 let mut error = ptr::null_mut(); 187 let _ = ffi::g_data_output_stream_put_byte( 188 self.as_ref().to_glib_none().0, 189 data, 190 cancellable.map(|p| p.as_ref()).to_glib_none().0, 191 &mut error, 192 ); 193 if error.is_null() { 194 Ok(()) 195 } else { 196 Err(from_glib_full(error)) 197 } 198 } 199 } 200 put_int16<P: IsA<Cancellable>>( &self, data: i16, cancellable: Option<&P>, ) -> Result<(), glib::Error>201 fn put_int16<P: IsA<Cancellable>>( 202 &self, 203 data: i16, 204 cancellable: Option<&P>, 205 ) -> Result<(), glib::Error> { 206 unsafe { 207 let mut error = ptr::null_mut(); 208 let _ = ffi::g_data_output_stream_put_int16( 209 self.as_ref().to_glib_none().0, 210 data, 211 cancellable.map(|p| p.as_ref()).to_glib_none().0, 212 &mut error, 213 ); 214 if error.is_null() { 215 Ok(()) 216 } else { 217 Err(from_glib_full(error)) 218 } 219 } 220 } 221 put_int32<P: IsA<Cancellable>>( &self, data: i32, cancellable: Option<&P>, ) -> Result<(), glib::Error>222 fn put_int32<P: IsA<Cancellable>>( 223 &self, 224 data: i32, 225 cancellable: Option<&P>, 226 ) -> Result<(), glib::Error> { 227 unsafe { 228 let mut error = ptr::null_mut(); 229 let _ = ffi::g_data_output_stream_put_int32( 230 self.as_ref().to_glib_none().0, 231 data, 232 cancellable.map(|p| p.as_ref()).to_glib_none().0, 233 &mut error, 234 ); 235 if error.is_null() { 236 Ok(()) 237 } else { 238 Err(from_glib_full(error)) 239 } 240 } 241 } 242 put_int64<P: IsA<Cancellable>>( &self, data: i64, cancellable: Option<&P>, ) -> Result<(), glib::Error>243 fn put_int64<P: IsA<Cancellable>>( 244 &self, 245 data: i64, 246 cancellable: Option<&P>, 247 ) -> Result<(), glib::Error> { 248 unsafe { 249 let mut error = ptr::null_mut(); 250 let _ = ffi::g_data_output_stream_put_int64( 251 self.as_ref().to_glib_none().0, 252 data, 253 cancellable.map(|p| p.as_ref()).to_glib_none().0, 254 &mut error, 255 ); 256 if error.is_null() { 257 Ok(()) 258 } else { 259 Err(from_glib_full(error)) 260 } 261 } 262 } 263 put_string<P: IsA<Cancellable>>( &self, str: &str, cancellable: Option<&P>, ) -> Result<(), glib::Error>264 fn put_string<P: IsA<Cancellable>>( 265 &self, 266 str: &str, 267 cancellable: Option<&P>, 268 ) -> Result<(), glib::Error> { 269 unsafe { 270 let mut error = ptr::null_mut(); 271 let _ = ffi::g_data_output_stream_put_string( 272 self.as_ref().to_glib_none().0, 273 str.to_glib_none().0, 274 cancellable.map(|p| p.as_ref()).to_glib_none().0, 275 &mut error, 276 ); 277 if error.is_null() { 278 Ok(()) 279 } else { 280 Err(from_glib_full(error)) 281 } 282 } 283 } 284 put_uint16<P: IsA<Cancellable>>( &self, data: u16, cancellable: Option<&P>, ) -> Result<(), glib::Error>285 fn put_uint16<P: IsA<Cancellable>>( 286 &self, 287 data: u16, 288 cancellable: Option<&P>, 289 ) -> Result<(), glib::Error> { 290 unsafe { 291 let mut error = ptr::null_mut(); 292 let _ = ffi::g_data_output_stream_put_uint16( 293 self.as_ref().to_glib_none().0, 294 data, 295 cancellable.map(|p| p.as_ref()).to_glib_none().0, 296 &mut error, 297 ); 298 if error.is_null() { 299 Ok(()) 300 } else { 301 Err(from_glib_full(error)) 302 } 303 } 304 } 305 put_uint32<P: IsA<Cancellable>>( &self, data: u32, cancellable: Option<&P>, ) -> Result<(), glib::Error>306 fn put_uint32<P: IsA<Cancellable>>( 307 &self, 308 data: u32, 309 cancellable: Option<&P>, 310 ) -> Result<(), glib::Error> { 311 unsafe { 312 let mut error = ptr::null_mut(); 313 let _ = ffi::g_data_output_stream_put_uint32( 314 self.as_ref().to_glib_none().0, 315 data, 316 cancellable.map(|p| p.as_ref()).to_glib_none().0, 317 &mut error, 318 ); 319 if error.is_null() { 320 Ok(()) 321 } else { 322 Err(from_glib_full(error)) 323 } 324 } 325 } 326 put_uint64<P: IsA<Cancellable>>( &self, data: u64, cancellable: Option<&P>, ) -> Result<(), glib::Error>327 fn put_uint64<P: IsA<Cancellable>>( 328 &self, 329 data: u64, 330 cancellable: Option<&P>, 331 ) -> Result<(), glib::Error> { 332 unsafe { 333 let mut error = ptr::null_mut(); 334 let _ = ffi::g_data_output_stream_put_uint64( 335 self.as_ref().to_glib_none().0, 336 data, 337 cancellable.map(|p| p.as_ref()).to_glib_none().0, 338 &mut error, 339 ); 340 if error.is_null() { 341 Ok(()) 342 } else { 343 Err(from_glib_full(error)) 344 } 345 } 346 } 347 set_byte_order(&self, order: DataStreamByteOrder)348 fn set_byte_order(&self, order: DataStreamByteOrder) { 349 unsafe { 350 ffi::g_data_output_stream_set_byte_order( 351 self.as_ref().to_glib_none().0, 352 order.into_glib(), 353 ); 354 } 355 } 356 connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId357 fn connect_byte_order_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 358 unsafe extern "C" fn notify_byte_order_trampoline< 359 P: IsA<DataOutputStream>, 360 F: Fn(&P) + 'static, 361 >( 362 this: *mut ffi::GDataOutputStream, 363 _param_spec: glib::ffi::gpointer, 364 f: glib::ffi::gpointer, 365 ) { 366 let f: &F = &*(f as *const F); 367 f(DataOutputStream::from_glib_borrow(this).unsafe_cast_ref()) 368 } 369 unsafe { 370 let f: Box_<F> = Box_::new(f); 371 connect_raw( 372 self.as_ptr() as *mut _, 373 b"notify::byte-order\0".as_ptr() as *const _, 374 Some(transmute::<_, unsafe extern "C" fn()>( 375 notify_byte_order_trampoline::<Self, F> as *const (), 376 )), 377 Box_::into_raw(f), 378 ) 379 } 380 } 381 } 382 383 impl fmt::Display for DataOutputStream { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result384 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 385 f.write_str("DataOutputStream") 386 } 387 } 388