gio/auto/
memory_output_stream.rs

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
5use 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
33mod sealed {
34    pub trait Sealed {}
35    impl<T: super::IsA<super::MemoryOutputStream>> Sealed for T {}
36}
37
38pub trait MemoryOutputStreamExt: IsA<MemoryOutputStream> + sealed::Sealed + 'static {
39    #[doc(alias = "g_memory_output_stream_get_data_size")]
40    #[doc(alias = "get_data_size")]
41    #[doc(alias = "data-size")]
42    fn data_size(&self) -> usize {
43        unsafe { ffi::g_memory_output_stream_get_data_size(self.as_ref().to_glib_none().0) }
44    }
45
46    #[doc(alias = "g_memory_output_stream_steal_as_bytes")]
47    fn steal_as_bytes(&self) -> glib::Bytes {
48        unsafe {
49            from_glib_full(ffi::g_memory_output_stream_steal_as_bytes(
50                self.as_ref().to_glib_none().0,
51            ))
52        }
53    }
54
55    #[doc(alias = "data-size")]
56    fn connect_data_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
57        unsafe extern "C" fn notify_data_size_trampoline<
58            P: IsA<MemoryOutputStream>,
59            F: Fn(&P) + 'static,
60        >(
61            this: *mut ffi::GMemoryOutputStream,
62            _param_spec: glib::ffi::gpointer,
63            f: glib::ffi::gpointer,
64        ) {
65            let f: &F = &*(f as *const F);
66            f(MemoryOutputStream::from_glib_borrow(this).unsafe_cast_ref())
67        }
68        unsafe {
69            let f: Box_<F> = Box_::new(f);
70            connect_raw(
71                self.as_ptr() as *mut _,
72                b"notify::data-size\0".as_ptr() as *const _,
73                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
74                    notify_data_size_trampoline::<Self, F> as *const (),
75                )),
76                Box_::into_raw(f),
77            )
78        }
79    }
80}
81
82impl<O: IsA<MemoryOutputStream>> MemoryOutputStreamExt for O {}