libshumate 0.8.0

Rust bindings for libshumate
// 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::{VectorValueType, ffi};
use glib::translate::*;

glib::wrapper! {
    #[derive(Debug, PartialOrd, Ord)]
    pub struct VectorValue(Boxed<ffi::ShumateVectorValue>);

    match fn {
        copy => |ptr| glib::gobject_ffi::g_boxed_copy(ffi::shumate_vector_value_get_type(), ptr as *mut _) as *mut ffi::ShumateVectorValue,
        free => |ptr| glib::gobject_ffi::g_boxed_free(ffi::shumate_vector_value_get_type(), ptr as *mut _),
        type_ => || ffi::shumate_vector_value_get_type(),
    }
}

impl VectorValue {
    #[doc(alias = "shumate_vector_value_new")]
    pub fn new() -> VectorValue {
        unsafe { from_glib_full(ffi::shumate_vector_value_new()) }
    }

    #[doc(alias = "shumate_vector_value_new_boolean")]
    pub fn new_boolean(boolean: bool) -> VectorValue {
        unsafe { from_glib_full(ffi::shumate_vector_value_new_boolean(boolean.into_glib())) }
    }

    #[doc(alias = "shumate_vector_value_new_color")]
    pub fn new_color(color: &gdk::RGBA) -> VectorValue {
        unsafe { from_glib_full(ffi::shumate_vector_value_new_color(color.to_glib_none().0)) }
    }

    #[doc(alias = "shumate_vector_value_new_from_value")]
    #[doc(alias = "new_from_value")]
    pub fn from_value(value: &glib::Value) -> VectorValue {
        unsafe {
            from_glib_full(ffi::shumate_vector_value_new_from_value(
                value.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "shumate_vector_value_new_number")]
    pub fn new_number(number: f64) -> VectorValue {
        unsafe { from_glib_full(ffi::shumate_vector_value_new_number(number)) }
    }

    #[doc(alias = "shumate_vector_value_new_string")]
    pub fn new_string(string: &str) -> VectorValue {
        unsafe {
            from_glib_full(ffi::shumate_vector_value_new_string(
                string.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "shumate_vector_value_array_append")]
    pub fn array_append(&mut self, element: &VectorValue) {
        unsafe {
            ffi::shumate_vector_value_array_append(
                self.to_glib_none_mut().0,
                mut_override(element.to_glib_none().0),
            );
        }
    }

    #[doc(hidden)]
    #[doc(alias = "shumate_vector_value_dup")]
    #[must_use]
    pub fn dup(&self) -> Option<VectorValue> {
        unsafe {
            from_glib_full(ffi::shumate_vector_value_dup(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    #[doc(alias = "shumate_vector_value_equal")]
    fn equal(&self, b: &VectorValue) -> bool {
        unsafe {
            from_glib(ffi::shumate_vector_value_equal(
                mut_override(self.to_glib_none().0),
                mut_override(b.to_glib_none().0),
            ))
        }
    }

    #[doc(alias = "shumate_vector_value_get_boolean")]
    #[doc(alias = "get_boolean")]
    pub fn boolean(&self) -> Option<bool> {
        unsafe {
            let mut boolean = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::shumate_vector_value_get_boolean(
                mut_override(self.to_glib_none().0),
                boolean.as_mut_ptr(),
            ));
            if ret {
                Some(from_glib(boolean.assume_init()))
            } else {
                None
            }
        }
    }

    #[doc(alias = "shumate_vector_value_get_color")]
    #[doc(alias = "get_color")]
    pub fn color(&self) -> Option<gdk::RGBA> {
        unsafe {
            let mut color = gdk::RGBA::uninitialized();
            let ret = from_glib(ffi::shumate_vector_value_get_color(
                mut_override(self.to_glib_none().0),
                color.to_glib_none_mut().0,
            ));
            if ret { Some(color) } else { None }
        }
    }

    #[doc(alias = "shumate_vector_value_get_number")]
    #[doc(alias = "get_number")]
    pub fn number(&self) -> Option<f64> {
        unsafe {
            let mut number = std::mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::shumate_vector_value_get_number(
                mut_override(self.to_glib_none().0),
                number.as_mut_ptr(),
            ));
            if ret {
                Some(number.assume_init())
            } else {
                None
            }
        }
    }

    #[doc(alias = "shumate_vector_value_get_value_type")]
    #[doc(alias = "get_value_type")]
    pub fn value_type(&self) -> VectorValueType {
        unsafe {
            from_glib(ffi::shumate_vector_value_get_value_type(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    #[doc(alias = "shumate_vector_value_hash")]
    fn hash(&self) -> i32 {
        unsafe { ffi::shumate_vector_value_hash(mut_override(self.to_glib_none().0)) }
    }

    #[doc(alias = "shumate_vector_value_is_null")]
    pub fn is_null(&self) -> bool {
        unsafe {
            from_glib(ffi::shumate_vector_value_is_null(mut_override(
                self.to_glib_none().0,
            )))
        }
    }

    #[doc(alias = "shumate_vector_value_set_boolean")]
    pub fn set_boolean(&mut self, boolean: bool) {
        unsafe {
            ffi::shumate_vector_value_set_boolean(self.to_glib_none_mut().0, boolean.into_glib());
        }
    }

    #[doc(alias = "shumate_vector_value_set_color")]
    pub fn set_color(&mut self, color: &gdk::RGBA) {
        unsafe {
            ffi::shumate_vector_value_set_color(self.to_glib_none_mut().0, color.to_glib_none().0);
        }
    }

    #[doc(alias = "shumate_vector_value_set_number")]
    pub fn set_number(&mut self, number: f64) {
        unsafe {
            ffi::shumate_vector_value_set_number(self.to_glib_none_mut().0, number);
        }
    }

    #[doc(alias = "shumate_vector_value_set_string")]
    pub fn set_string(&mut self, string: &str) {
        unsafe {
            ffi::shumate_vector_value_set_string(
                self.to_glib_none_mut().0,
                string.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "shumate_vector_value_start_array")]
    pub fn start_array(&mut self) {
        unsafe {
            ffi::shumate_vector_value_start_array(self.to_glib_none_mut().0);
        }
    }

    #[doc(alias = "shumate_vector_value_unset")]
    pub fn unset(&mut self) {
        unsafe {
            ffi::shumate_vector_value_unset(self.to_glib_none_mut().0);
        }
    }
}

#[cfg(feature = "v1_6")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_6")))]
impl Default for VectorValue {
    fn default() -> Self {
        Self::new()
    }
}

impl PartialEq for VectorValue {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.equal(other)
    }
}

impl Eq for VectorValue {}

impl std::hash::Hash for VectorValue {
    #[inline]
    fn hash<H>(&self, state: &mut H)
    where
        H: std::hash::Hasher,
    {
        std::hash::Hash::hash(&self.hash(), state)
    }
}