sourceview5 0.11.0

Rust bindings for GtkSourceView 5
Documentation
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::ffi;
use glib::translate::*;

glib::wrapper! {
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct Encoding(Boxed<ffi::GtkSourceEncoding>);

    match fn {
        copy => |ptr| ffi::gtk_source_encoding_copy(ptr),
        free => |ptr| ffi::gtk_source_encoding_free(ptr),
        type_ => || ffi::gtk_source_encoding_get_type(),
    }
}

impl Encoding {
    #[doc(alias = "gtk_source_encoding_get_charset")]
    #[doc(alias = "get_charset")]
    pub fn charset(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::gtk_source_encoding_get_charset(self.to_glib_none().0)) }
    }

    #[doc(alias = "gtk_source_encoding_get_name")]
    #[doc(alias = "get_name")]
    pub fn name(&self) -> glib::GString {
        unsafe { from_glib_none(ffi::gtk_source_encoding_get_name(self.to_glib_none().0)) }
    }

    #[doc(alias = "gtk_source_encoding_to_string")]
    #[doc(alias = "to_string")]
    pub fn to_str(&self) -> glib::GString {
        unsafe { from_glib_full(ffi::gtk_source_encoding_to_string(self.to_glib_none().0)) }
    }

    #[doc(alias = "gtk_source_encoding_get_all")]
    #[doc(alias = "get_all")]
    pub fn all() -> Vec<Encoding> {
        assert_initialized_main_thread!();
        unsafe { FromGlibPtrContainer::from_glib_container(ffi::gtk_source_encoding_get_all()) }
    }

    #[doc(alias = "gtk_source_encoding_get_current")]
    #[doc(alias = "get_current")]
    pub fn current() -> Encoding {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gtk_source_encoding_get_current()) }
    }

    #[doc(alias = "gtk_source_encoding_get_default_candidates")]
    #[doc(alias = "get_default_candidates")]
    pub fn default_candidates() -> Vec<Encoding> {
        assert_initialized_main_thread!();
        unsafe {
            FromGlibPtrContainer::from_glib_container(
                ffi::gtk_source_encoding_get_default_candidates(),
            )
        }
    }

    #[doc(alias = "gtk_source_encoding_get_from_charset")]
    #[doc(alias = "get_from_charset")]
    pub fn from_charset(charset: &str) -> Option<Encoding> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(ffi::gtk_source_encoding_get_from_charset(
                charset.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "gtk_source_encoding_get_utf8")]
    #[doc(alias = "get_utf8")]
    pub fn utf8() -> Encoding {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gtk_source_encoding_get_utf8()) }
    }
}

impl std::fmt::Display for Encoding {
    #[inline]
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(&self.to_str())
    }
}