gio/auto/
memory_output_stream.rs1use crate::{ffi, OutputStream, PollableOutputStream, Seekable};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GMemoryOutputStream")]
15 pub struct MemoryOutputStream(Object<ffi::GMemoryOutputStream, ffi::GMemoryOutputStreamClass>) @extends OutputStream, @implements PollableOutputStream, Seekable;
16
17 match fn {
18 type_ => || ffi::g_memory_output_stream_get_type(),
19 }
20}
21
22impl MemoryOutputStream {
23 pub const NONE: Option<&'static MemoryOutputStream> = None;
24
25 #[doc(alias = "g_memory_output_stream_new_resizable")]
26 pub fn new_resizable() -> MemoryOutputStream {
27 unsafe {
28 OutputStream::from_glib_full(ffi::g_memory_output_stream_new_resizable()).unsafe_cast()
29 }
30 }
31}
32
33pub trait MemoryOutputStreamExt: IsA<MemoryOutputStream> + 'static {
34 #[doc(alias = "g_memory_output_stream_get_data_size")]
35 #[doc(alias = "get_data_size")]
36 #[doc(alias = "data-size")]
37 fn data_size(&self) -> usize {
38 unsafe { ffi::g_memory_output_stream_get_data_size(self.as_ref().to_glib_none().0) }
39 }
40
41 #[doc(alias = "g_memory_output_stream_steal_as_bytes")]
42 fn steal_as_bytes(&self) -> glib::Bytes {
43 unsafe {
44 from_glib_full(ffi::g_memory_output_stream_steal_as_bytes(
45 self.as_ref().to_glib_none().0,
46 ))
47 }
48 }
49
50 #[doc(alias = "data-size")]
51 fn connect_data_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
52 unsafe extern "C" fn notify_data_size_trampoline<
53 P: IsA<MemoryOutputStream>,
54 F: Fn(&P) + 'static,
55 >(
56 this: *mut ffi::GMemoryOutputStream,
57 _param_spec: glib::ffi::gpointer,
58 f: glib::ffi::gpointer,
59 ) {
60 let f: &F = &*(f as *const F);
61 f(MemoryOutputStream::from_glib_borrow(this).unsafe_cast_ref())
62 }
63 unsafe {
64 let f: Box_<F> = Box_::new(f);
65 connect_raw(
66 self.as_ptr() as *mut _,
67 c"notify::data-size".as_ptr() as *const _,
68 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
69 notify_data_size_trampoline::<Self, F> as *const (),
70 )),
71 Box_::into_raw(f),
72 )
73 }
74 }
75}
76
77impl<O: IsA<MemoryOutputStream>> MemoryOutputStreamExt for O {}