Skip to main content

gtk4/
try_expression.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{Expression, TryExpression, ffi};
6
7define_expression!(TryExpression, crate::ffi::GtkTryExpression);
8
9impl TryExpression {
10    /// Creates a [`Expression`][crate::Expression] with an array of expressions.
11    ///
12    /// When evaluated, the [`TryExpression`][crate::TryExpression] tries to evaluate each of its expressions until it succeeds.
13    /// If all expressions fail to evaluate, the [`TryExpression`][crate::TryExpression]'s evaluation fails as well.
14    ///
15    /// The value type of the expressions in the array must match.
16    /// ## `expressions`
17    /// The array of expressions
18    ///
19    /// # Returns
20    ///
21    /// a new [`Expression`][crate::Expression]
22    #[doc(alias = "gtk_try_expression_new")]
23    pub fn new(params: impl IntoIterator<Item = impl AsRef<Expression>>) -> Self {
24        assert_initialized_main_thread!();
25
26        let params = params
27            .into_iter()
28            .map(|e| e.as_ref().clone())
29            .collect::<Vec<_>>();
30
31        unsafe {
32            from_glib_full(ffi::gtk_try_expression_new(
33                params.len() as u32,
34                params.to_glib_full(),
35            ))
36        }
37    }
38}