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
34mod sealed {
35    pub trait Sealed {}
36    impl<T: super::IsA<super::Converter>> Sealed for T {}
37}
38
39/// Trait containing all [`struct@Converter`] methods.
40///
41/// # Implementors
42///
43/// [`CharsetConverter`][struct@crate::CharsetConverter], [`Converter`][struct@crate::Converter], [`ZlibCompressor`][struct@crate::ZlibCompressor], [`ZlibDecompressor`][struct@crate::ZlibDecompressor]
44pub trait ConverterExt: IsA<Converter> + sealed::Sealed + 'static {
45    /// Applies @self to the data in @bytes.
46    /// ## `bytes`
47    /// the data to convert
48    ///
49    /// # Returns
50    ///
51    /// A newly-allocated
52    ///   `GBytes` with the converted data, or `NULL` if an error
53    ///   occurred
54    #[cfg(feature = "v2_82")]
55    #[cfg_attr(docsrs, doc(cfg(feature = "v2_82")))]
56    #[doc(alias = "g_converter_convert_bytes")]
57    fn convert_bytes(&self, bytes: &glib::Bytes) -> Result<glib::Bytes, glib::Error> {
58        unsafe {
59            let mut error = std::ptr::null_mut();
60            let ret = ffi::g_converter_convert_bytes(
61                self.as_ref().to_glib_none().0,
62                bytes.to_glib_none().0,
63                &mut error,
64            );
65            if error.is_null() {
66                Ok(from_glib_full(ret))
67            } else {
68                Err(from_glib_full(error))
69            }
70        }
71    }
72
73    /// Resets all internal state in the converter, making it behave
74    /// as if it was just created. If the converter has any internal
75    /// state that would produce output then that output is lost.
76    #[doc(alias = "g_converter_reset")]
77    fn reset(&self) {
78        unsafe {
79            ffi::g_converter_reset(self.as_ref().to_glib_none().0);
80        }
81    }
82}
83
84impl<O: IsA<Converter>> ConverterExt for O {}