1use glib::{Value, translate::*, value::FromValue};
4
5use crate::ffi;
6
7glib::wrapper! {
8 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
13 #[doc(alias = "GtkExpressionWatch")]
14 pub struct ExpressionWatch(Shared<ffi::GtkExpressionWatch>);
15
16 match fn {
17 ref => |ptr| ffi::gtk_expression_watch_ref(ptr),
18 unref => |ptr| ffi::gtk_expression_watch_unref(ptr),
19 }
20}
21
22impl ExpressionWatch {
23 #[doc(alias = "gtk_expression_watch_evaluate")]
35 pub fn evaluate(&self) -> Option<Value> {
36 assert_initialized_main_thread!();
37 unsafe {
38 let mut value = Value::uninitialized();
39 let ret = ffi::gtk_expression_watch_evaluate(
40 self.to_glib_none().0,
41 value.to_glib_none_mut().0,
42 );
43 if from_glib(ret) { Some(value) } else { None }
44 }
45 }
46
47 #[doc(alias = "gtk_expression_evaluate")]
51 pub fn evaluate_as<V: for<'b> FromValue<'b> + 'static>(&self) -> Option<V> {
52 self.evaluate().map(|v| {
53 v.get_owned::<V>()
54 .expect("Failed to evaluate to this value type")
55 })
56 }
57
58 #[doc(alias = "gtk_expression_watch_unwatch")]
63 pub fn unwatch(&self) {
64 unsafe { ffi::gtk_expression_watch_unwatch(self.to_glib_none().0) }
65 }
66}
67
68#[cfg(feature = "v4_2")]
69impl glib::prelude::StaticType for ExpressionWatch {
70 #[doc(alias = "gtk_expression_watch_get_type")]
71 #[inline]
72 fn static_type() -> glib::Type {
73 unsafe { from_glib(ffi::gtk_expression_watch_get_type()) }
74 }
75}