extendr_api/wrapper/
expr.rs

1use super::*;
2
3#[derive(PartialEq, Clone)]
4pub struct Expressions {
5    pub(crate) robj: Robj,
6}
7
8impl Expressions {
9    /// Wrapper for creating Expressions (EXPRSXP) objects.
10    pub fn new() -> Self {
11        Expressions::from_values([Robj::from(()); 0])
12    }
13
14    /// Wrapper for creating Expressions (EXPRSXP) objects.
15    /// ```
16    /// use extendr_api::prelude::*;
17    /// test! {
18    ///     let expr = r!(Expressions::from_values(&[r!(0), r!(1), r!(2)]));
19    ///     assert_eq!(expr.is_expressions(), true);
20    ///     assert_eq!(expr.len(), 3);
21    /// }
22    /// ```
23    pub fn from_values<V>(values: V) -> Self
24    where
25        V: IntoIterator,
26        V::IntoIter: ExactSizeIterator,
27        V::Item: Into<Robj>,
28    {
29        Self {
30            robj: make_vector(SEXPTYPE::EXPRSXP, values),
31        }
32    }
33
34    /// Return an iterator over the values of this expression list.
35    pub fn values(&self) -> ListIter {
36        ListIter::from_parts(self.robj.clone(), 0, self.robj.len())
37    }
38}
39
40impl std::default::Default for Expressions {
41    fn default() -> Self {
42        Expressions::new()
43    }
44}
45
46impl std::fmt::Debug for Expressions {
47    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
48        f.debug_struct("Expressions")
49            .field("values", &self.values())
50            .finish()
51    }
52}