Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deserializing from R into a struct #21

Open
JosiahParry opened this issue Mar 2, 2024 · 1 comment
Open

deserializing from R into a struct #21

JosiahParry opened this issue Mar 2, 2024 · 1 comment

Comments

@JosiahParry
Copy link
Contributor

Discovered this yesterday. Wrote an impl method like so:

For a lot of simple structs, we can deserialize from an R list object directly into that struct. This is very handy if we want to be able to accept R objects like lists instead of having to create external pointers to structs

use extendr_api::prelude::*;
use extendr_api::deserializer::from_robj;

use ast_grep_config::SerializableRule;
pub fn new_rule(pattern: Robj) -> SerializableRule {
    let r: SerializableRule = from_robj(&pattern).unwrap();
    r
}
@CGMossa
Copy link
Member

CGMossa commented Mar 5, 2024

I've also made another discovery: https://extendr.github.io/extendr/extendr_macros/derive.IntoRobj.html
I believe it does the same thing, where each field is extracted using dollar and a conversion is performed.

This should be renamed to IntoList or IntoRList.

@CGMossa CGMossa transferred this issue from extendr/user-guide-old Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants