Trait extendr_api::robj::Types

source ·
pub trait Types: GetSexp {
    // Provided methods
    fn rtype(&self) -> Rtype { ... }
    fn as_any(&self) -> Rany<'_> { ... }
}

Provided Methods§

source

fn rtype(&self) -> Rtype

Get the type of an R object.

use extendr_api::prelude::*;
test! {
    assert_eq!(r!(NULL).rtype(), Rtype::Null);
    assert_eq!(sym!(xyz).rtype(), Rtype::Symbol);
    assert_eq!(r!(Pairlist::from_pairs(vec![("a", r!(1))])).rtype(), Rtype::Pairlist);
    assert_eq!(R!("function() {}")?.rtype(), Rtype::Function);
    assert_eq!(Environment::new_with_parent(global_env()).rtype(), Rtype::Environment);
    assert_eq!(lang!("+", 1, 2).rtype(), Rtype::Language);
    assert_eq!(r!(Primitive::from_string("if")).rtype(), Rtype::Special);
    assert_eq!(r!(Primitive::from_string("+")).rtype(), Rtype::Builtin);
    assert_eq!(r!(Rstr::from_string("hello")).rtype(), Rtype::Rstr);
    assert_eq!(r!(TRUE).rtype(), Rtype::Logicals);
    assert_eq!(r!(1).rtype(), Rtype::Integers);
    assert_eq!(r!(1.0).rtype(), Rtype::Doubles);
    assert_eq!(r!("1").rtype(), Rtype::Strings);
    assert_eq!(r!(List::from_values(&[1, 2])).rtype(), Rtype::List);
    assert_eq!(parse("x + y")?.rtype(), Rtype::Expressions);
    assert_eq!(r!(Raw::from_bytes(&[1_u8, 2, 3])).rtype(), Rtype::Raw);
}
source

fn as_any(&self) -> Rany<'_>

Implementors§

source§

impl Types for Altrep

rtype() and rany()

source§

impl Types for Complexes

rtype() and rany()

source§

impl Types for Doubles

rtype() and rany()

source§

impl Types for Environment

rtype() and rany()

source§

impl Types for Expressions

rtype() and rany()

source§

impl Types for Function

rtype() and rany()

source§

impl Types for Integers

rtype() and rany()

source§

impl Types for Language

rtype() and rany()

source§

impl Types for List

rtype() and rany()

source§

impl Types for Logicals

rtype() and rany()

source§

impl Types for Pairlist

rtype() and rany()

source§

impl Types for Primitive

rtype() and rany()

source§

impl Types for Promise

rtype() and rany()

source§

impl Types for Raw

rtype() and rany()

source§

impl Types for Rstr

rtype() and rany()

source§

impl Types for S4

rtype() and rany()

source§

impl Types for Strings

rtype() and rany()

source§

impl Types for Symbol

rtype() and rany()

source§

impl Types for Robj

source§

impl<T> Types for Dataframe<T>

rtype() and rany()

source§

impl<T> Types for ExternalPtr<T>

rtype() and rany()