Skip to content

Does struct field renaming support private fields? #2397

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

Open
disconsented opened this issue Dec 14, 2020 · 3 comments
Open

Does struct field renaming support private fields? #2397

disconsented opened this issue Dec 14, 2020 · 3 comments
Labels

Comments

@disconsented
Copy link

I am trying to map across the stripe.CreatePaymentMethod function, but I am running into a bit of a blocker.

Because type is a keyboard it cannot be used as an attribute name thankfully #2360 was pulled in and I've ended up with the following:

#[wasm_bindgen]
pub struct PaymentMethodData{
    #[wasm_bindgen(js_name = type)]
    foo: String,
    card: Card,
    billing_details: BillingDetails,
}

card is a JS type and BillingDetails is a struct.

However, the following results in the following from the compiler:
error: expected an inert attribute, found an attribute macro

I have also tried:

#[wasm_bindgen]
pub struct PaymentMethodData{
    r#type: String,
    card: Arc<Card>,
    billing_details: BillingDetails,
}

Which does compile but stripe throws a runtime error (IntegrationError: Invalid value for createPaymentMethod: type should be string. You specified: undefined.).

Any ideas on where to go from here?

@alexcrichton
Copy link
Contributor

I don't think that private fields are exported into JS, so if you're passing this to an API that expects to be able to access a type property then that won't work? You'll need to probably make an impl with methods that work as accessors?

@disconsented
Copy link
Author

Okay I've finally figured out what is going on, internally stripe elements is accessing using bracket notation which is where the issue has cropped up from.

var i = r[o]

Where r is the object and o is a string with a field name, is there a way to expose fields for this or would I need to write a small translation layer?

@alexcrichton
Copy link
Contributor

Ah that makes sense! I'm unfortunately not enough of a JS-wizard to know what the options available to wasm-bindgen are to solve that. I'd probably have a small layer for now to translate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants