gdk: add nicer variant of ExpressionWatch::evaluate
// Take a look at the license at the top of the repository in the LICENSE file.
use glib::translate::*;
+use glib::value::FromValue;
use glib::Value;
glib::wrapper! {
@@ -32,6 +33,16 @@ impl ExpressionWatch {
}
}
+ // rustdoc-stripper-ignore-next
+ /// Similar to [`Self::evaluate`] but panics if the value is of a different type.
+ #[doc(alias = "gtk_expression_evaluate")]
+ pub fn evaluate_as<V: for<'b> FromValue<'b> + 'static>(&self) -> Option<V> {
+ self.evaluate().map(|v| {
+ v.get_owned::<V>()
+ .expect("Failed to evaluate to this value type")
+ })
+ }
+
#[doc(alias = "gtk_expression_watch_unwatch")]
pub fn unwatch(&self) {
unsafe { ffi::gtk_expression_watch_unwatch(self.to_glib_none().0) }
