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

Encode/Decode tuple structs #258

Closed
evnu opened this issue Oct 18, 2019 · 1 comment · Fixed by #259
Closed

Encode/Decode tuple structs #258

evnu opened this issue Oct 18, 2019 · 1 comment · Fixed by #259
Assignees

Comments

@evnu
Copy link
Member

evnu commented Oct 18, 2019

As mentioned here by @davydog187:

This also brings up another issue, as far as I can tell, tuple structs and newtypes are not encodeable/decodeable

So the following should be possible:

#[derive(NifTuple)]
pub struct Newtype(i64);

#[derive(NifTuple)]
pub struct TupleStruct(i64, i64, i64);

#[derive(NifRecord)]
#[tag = "newtype"]
pub struct Newtype(i64);

#[derive(NifRecord)]
#[module = "tuplestruct"]
pub struct TupleStruct(i64, i64, i64);
@evnu evnu self-assigned this Oct 19, 2019
@evnu
Copy link
Member Author

evnu commented Oct 19, 2019

While implementing this, I found a handy way to debug the quote output. This might be interesting to others as well:

#[proc_macro_derive(NifTuple, attributes(rustler))]
pub fn nif_tuple(input: TokenStream) -> TokenStream {
    let ast = syn::parse(input).unwrap();
    let tokens: TokenStream = tuple::transcoder_decorator(&ast).into();
    panic!("{}", TokenStream::to_string(&tokens));
    tokens
}

This aborts code generation with a panic and prints the generated code.

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

Successfully merging a pull request may close this issue.

1 participant