extendr_api::wrapper::wrapper_macros

Trait Conversions

Source
pub trait Conversions: GetSexp {
    // Provided methods
    fn as_symbol(&self) -> Option<Symbol> { ... }
    fn as_char(&self) -> Option<Rstr> { ... }
    fn as_raw(&self) -> Option<Raw> { ... }
    fn as_language(&self) -> Option<Language> { ... }
    fn as_pairlist(&self) -> Option<Pairlist> { ... }
    fn as_list(&self) -> Option<List> { ... }
    fn as_expressions(&self) -> Option<Expressions> { ... }
    fn as_environment(&self) -> Option<Environment> { ... }
    fn as_function(&self) -> Option<Function> { ... }
    fn as_promise(&self) -> Option<Promise> { ... }
}

Provided Methods§

Source

fn as_symbol(&self) -> Option<Symbol>

Convert a symbol object to a Symbol wrapper.

use extendr_api::prelude::*;
test! {
    let fred = sym!(fred);
    assert_eq!(fred.as_symbol(), Some(Symbol::from_string("fred")));
}
Source

fn as_char(&self) -> Option<Rstr>

Convert a CHARSXP object to a Rstr wrapper.

use extendr_api::prelude::*;
test! {
    let fred = Rstr::from_string("fred");
    assert_eq!(fred.as_char(), Some(Rstr::from_string("fred")));
}
Source

fn as_raw(&self) -> Option<Raw>

Convert a raw object to a Rstr wrapper.

use extendr_api::prelude::*;
test! {
    let bytes = r!(Raw::from_bytes(&[1, 2, 3]));
    assert_eq!(bytes.len(), 3);
    assert_eq!(bytes.as_raw(), Some(Raw::from_bytes(&[1, 2, 3])));
}
Source

fn as_language(&self) -> Option<Language>

Convert a language object to a Language wrapper.

use extendr_api::prelude::*;
test! {
    let call_to_xyz = r!(Language::from_values(&[r!(Symbol::from_string("xyz")), r!(1), r!(2)]));
    assert_eq!(call_to_xyz.is_language(), true);
    assert_eq!(call_to_xyz.len(), 3);
}
Source

fn as_pairlist(&self) -> Option<Pairlist>

Convert a pair list object (LISTSXP) to a Pairlist wrapper.

use extendr_api::prelude::*;
test! {
    let names_and_values = vec![("a", r!(1)), ("b", r!(2)), ("", r!(3))];
    let pairlist = Pairlist::from_pairs(names_and_values);
    let robj = r!(pairlist.clone());
    assert_eq!(robj.as_pairlist().unwrap(), pairlist);
}
Source

fn as_list(&self) -> Option<List>

Convert a list object (VECSXP) to a List wrapper.

use extendr_api::prelude::*;
test! {
    let list = r!(List::from_values(&[r!(0), r!(1), r!(2)]));
    assert_eq!(list.is_list(), true);
}
Source

fn as_expressions(&self) -> Option<Expressions>

Convert an expression object (EXPRSXP) to a Expr wrapper.

use extendr_api::prelude::*;
test! {
    let expr = r!(Expressions::from_values(&[r!(0), r!(1), r!(2)]));
    assert_eq!(expr.is_expressions(), true);
    assert_eq!(expr.as_expressions(), Some(Expressions::from_values(vec![r!(0), r!(1), r!(2)])));
}
Source

fn as_environment(&self) -> Option<Environment>

Convert an environment object (ENVSXP) to a Env wrapper.

use extendr_api::prelude::*;
test! {
    let names_and_values = (0..100).map(|i| (format!("n{}", i), i));
    let env = Environment::from_pairs(global_env(), names_and_values);
    let expr = env.clone();
    assert_eq!(expr.len(), 100);
    let env2 = expr.as_environment().unwrap();
    assert_eq!(env2.len(), 100);
}
Source

fn as_function(&self) -> Option<Function>

Convert a function object (CLOSXP) to a Function wrapper.

use extendr_api::prelude::*;
test! {
    let func = R!("function(a,b) a + b").unwrap();
    println!("{:?}", func.as_function());
}
Source

fn as_promise(&self) -> Option<Promise>

Get a wrapper for a promise.

Implementors§