gio/auto/memory_input_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, InputStream, PollableInputStream, Seekable};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// `GMemoryInputStream` is a class for using arbitrary
10 /// memory chunks as input for GIO streaming input operations.
11 ///
12 /// As of GLib 2.34, `GMemoryInputStream` implements
13 /// [`PollableInputStream`][crate::PollableInputStream].
14 ///
15 /// # Implements
16 ///
17 /// [`MemoryInputStreamExt`][trait@crate::prelude::MemoryInputStreamExt], [`InputStreamExt`][trait@crate::prelude::InputStreamExt], [`trait@glib::ObjectExt`], [`PollableInputStreamExt`][trait@crate::prelude::PollableInputStreamExt], [`SeekableExt`][trait@crate::prelude::SeekableExt], [`InputStreamExtManual`][trait@crate::prelude::InputStreamExtManual], [`PollableInputStreamExtManual`][trait@crate::prelude::PollableInputStreamExtManual]
18 #[doc(alias = "GMemoryInputStream")]
19 pub struct MemoryInputStream(Object<ffi::GMemoryInputStream, ffi::GMemoryInputStreamClass>) @extends InputStream, @implements PollableInputStream, Seekable;
20
21 match fn {
22 type_ => || ffi::g_memory_input_stream_get_type(),
23 }
24}
25
26impl MemoryInputStream {
27 pub const NONE: Option<&'static MemoryInputStream> = None;
28
29 /// Creates a new empty #GMemoryInputStream.
30 ///
31 /// # Returns
32 ///
33 /// a new #GInputStream
34 #[doc(alias = "g_memory_input_stream_new")]
35 pub fn new() -> MemoryInputStream {
36 unsafe { InputStream::from_glib_full(ffi::g_memory_input_stream_new()).unsafe_cast() }
37 }
38
39 /// Creates a new #GMemoryInputStream with data from the given @bytes.
40 /// ## `bytes`
41 /// a #GBytes
42 ///
43 /// # Returns
44 ///
45 /// new #GInputStream read from @bytes
46 #[doc(alias = "g_memory_input_stream_new_from_bytes")]
47 #[doc(alias = "new_from_bytes")]
48 pub fn from_bytes(bytes: &glib::Bytes) -> MemoryInputStream {
49 unsafe {
50 InputStream::from_glib_full(ffi::g_memory_input_stream_new_from_bytes(
51 bytes.to_glib_none().0,
52 ))
53 .unsafe_cast()
54 }
55 }
56}
57
58impl Default for MemoryInputStream {
59 fn default() -> Self {
60 Self::new()
61 }
62}
63
64mod sealed {
65 pub trait Sealed {}
66 impl<T: super::IsA<super::MemoryInputStream>> Sealed for T {}
67}
68
69/// Trait containing all [`struct@MemoryInputStream`] methods.
70///
71/// # Implementors
72///
73/// [`MemoryInputStream`][struct@crate::MemoryInputStream]
74pub trait MemoryInputStreamExt: IsA<MemoryInputStream> + sealed::Sealed + 'static {
75 /// Appends @bytes to data that can be read from the input stream.
76 /// ## `bytes`
77 /// input data
78 #[doc(alias = "g_memory_input_stream_add_bytes")]
79 fn add_bytes(&self, bytes: &glib::Bytes) {
80 unsafe {
81 ffi::g_memory_input_stream_add_bytes(
82 self.as_ref().to_glib_none().0,
83 bytes.to_glib_none().0,
84 );
85 }
86 }
87}
88
89impl<O: IsA<MemoryInputStream>> MemoryInputStreamExt for O {}