logo
pub fn to_robj<T>(value: &T) -> Result<Robj> where
    T: Serialize
Expand description

Convert a serializable object to a Robj.

Requires the “serde” feature.

extendr-api = { version = "0", features = ["serde"] }

Example:

use extendr_api::prelude::*;
use extendr_api::serializer::to_robj;
use serde::Serialize;
test! {
    #[derive(Serialize)]
    struct Test {
        int: i32,
        seq: Vec<&'static str>,
    }

    let test = Test {
        int: 1,
        seq: vec!["a", "b"],
    };

    let expected = list!(int=1, seq=list!("a", "b"));
    assert_eq!(to_robj(&test).unwrap(), Robj::from(expected));
}