gio/auto/converter.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;
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// `GConverter` is an interface for streaming conversions.
10 ///
11 /// `GConverter` is implemented by objects that convert
12 /// binary data in various ways. The conversion can be
13 /// stateful and may fail at any place.
14 ///
15 /// Some example conversions are: character set conversion,
16 /// compression, decompression and regular expression
17 /// replace.
18 ///
19 /// # Implements
20 ///
21 /// [`ConverterExt`][trait@crate::prelude::ConverterExt], [`ConverterExtManual`][trait@crate::prelude::ConverterExtManual]
22 #[doc(alias = "GConverter")]
23 pub struct Converter(Interface<ffi::GConverter, ffi::GConverterIface>);
24
25 match fn {
26 type_ => || ffi::g_converter_get_type(),
27 }
28}
29
30impl Converter {
31 pub const NONE: Option<&'static Converter> = None;
32}
33
34/// Trait containing all [`struct@Converter`] methods.
35///
36/// # Implementors
37///
38/// [`CharsetConverter`][struct@crate::CharsetConverter], [`Converter`][struct@crate::Converter], [`ZlibCompressor`][struct@crate::ZlibCompressor], [`ZlibDecompressor`][struct@crate::ZlibDecompressor]
39pub trait ConverterExt: IsA<Converter> + 'static {
40 /// Applies @self to the data in @bytes.
41 /// ## `bytes`
42 /// the data to convert
43 ///
44 /// # Returns
45 ///
46 /// A newly-allocated
47 /// `GBytes` with the converted data, or `NULL` if an error
48 /// occurred
49 #[cfg(feature = "v2_82")]
50 #[cfg_attr(docsrs, doc(cfg(feature = "v2_82")))]
51 #[doc(alias = "g_converter_convert_bytes")]
52 fn convert_bytes(&self, bytes: &glib::Bytes) -> Result<glib::Bytes, glib::Error> {
53 unsafe {
54 let mut error = std::ptr::null_mut();
55 let ret = ffi::g_converter_convert_bytes(
56 self.as_ref().to_glib_none().0,
57 bytes.to_glib_none().0,
58 &mut error,
59 );
60 if error.is_null() {
61 Ok(from_glib_full(ret))
62 } else {
63 Err(from_glib_full(error))
64 }
65 }
66 }
67
68 /// Resets all internal state in the converter, making it behave
69 /// as if it was just created. If the converter has any internal
70 /// state that would produce output then that output is lost.
71 #[doc(alias = "g_converter_reset")]
72 fn reset(&self) {
73 unsafe {
74 ffi::g_converter_reset(self.as_ref().to_glib_none().0);
75 }
76 }
77}
78
79impl<O: IsA<Converter>> ConverterExt for O {}