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

Provide inline_js snippets from an &str #2787

Open
jkelleyrtp opened this issue Feb 3, 2022 · 0 comments
Open

Provide inline_js snippets from an &str #2787

jkelleyrtp opened this issue Feb 3, 2022 · 0 comments

Comments

@jkelleyrtp
Copy link

jkelleyrtp commented Feb 3, 2022

Motivation

To use inline JS snippets today, you need to include the literal directly. However, this only makes sense through code generation where the literal is assembled from another file.

If you're in my position with an extra crate full of snippets, you need to code generate for every module. Using code generation like this is typically not popular in the Rust ecosystem.

Proposed Solution

inline_js (or another label) should support &'static str passed in, allowing for things like include_str! and &str imported from other crates.

We could then structure the _INCLUDED_FILES section to just reference the literal directly, since I don't think there's any validation of the JS snippet code.

#[allow(non_upper_case_globals)]
#[cfg(target_arch = "wasm32")]
#[link_section = "__wasm_bindgen_unstable"]
#[doc(hidden)]
#[allow(clippy::all)]
pub static __WASM_BINDGEN_GENERATED_84d6b6512bbd6f6d:[u8;
19080usize] = {
  static _INCLUDED_FILES: &[&str] =  &[];
};

Alternatives

Really the only way to share source JS code between different crates right now is code generation.

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

1 participant