javascriptcore6 0.6.0

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

use crate::{Value, ffi};
use glib::{
    object::ObjectType as _,
    prelude::*,
    signal::{SignalHandlerId, connect_raw},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    #[doc(alias = "JSCWeakValue")]
    pub struct WeakValue(Object<ffi::JSCWeakValue, ffi::JSCWeakValueClass>);

    match fn {
        type_ => || ffi::jsc_weak_value_get_type(),
    }
}

impl WeakValue {
    #[doc(alias = "jsc_weak_value_new")]
    pub fn new(value: &Value) -> WeakValue {
        skip_assert_initialized!();
        unsafe { from_glib_full(ffi::jsc_weak_value_new(value.to_glib_none().0)) }
    }

    #[doc(alias = "jsc_weak_value_get_value")]
    #[doc(alias = "get_value")]
    pub fn value(&self) -> Option<Value> {
        unsafe { from_glib_full(ffi::jsc_weak_value_get_value(self.to_glib_none().0)) }
    }

    #[doc(alias = "cleared")]
    pub fn connect_cleared<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn cleared_trampoline<F: Fn(&WeakValue) + 'static>(
            this: *mut ffi::JSCWeakValue,
            f: glib::ffi::gpointer,
        ) {
            unsafe {
                let f: &F = &*(f as *const F);
                f(&from_glib_borrow(this))
            }
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                c"cleared".as_ptr(),
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    cleared_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}