gtk: add a nicer variant of Expression::evaluate
use crate::ExpressionWatch;
use glib::translate::*;
-use glib::{IsA, Object, StaticType, Type, Value};
+use glib::{value::FromValue, IsA, Object, StaticType, Type, Value};
use std::boxed::Box as Box_;
glib::wrapper! {
@@ -121,6 +121,19 @@ impl Expression {
}
}
+ // 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, T: IsA<Object>>(
+ &self,
+ this: Option<&T>,
+ ) -> Option<V> {
+ self.evaluate(this).map(|v| {
+ v.get_owned::<V>()
+ .expect("Failed to evaluate to this value type")
+ })
+ }
+
#[doc(alias = "gtk_expression_watch")]
pub fn watch<T: IsA<Object>, F: Fn() + 'static>(
&self,
