-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Integration with wasm-bindgen #196
Comments
This would be cool but I think it is way more difficult than you would expect. Specta works fully at runtime making use of Rust's trait system to resolve types while Tauri bindgen works fully through static analysis which is just looking at the file content. As a workaround, you could technically generate a If Specta ever had a CLI we could definitely support this but I really don't think that will happen. Resolving types using static analysis would be both significantly less reliable and require us to maintain a completely different implementation. At that point you'd probs be best with Typeshare with it's drawbacks. For future me:
|
Yes, right now I don't think it is possible, the only real way I see this working would be with support in Right now, what I think the best way is (although a bit yank) is to have an example like Another thing to mention is that the current |
Can you share the error, that is definitely something I can look into fixing. |
#[wasm_bindgen::prelude::wasm_bindgen]
#[specta::specta]
pub async fn create_account(
client: &__wasm::AccountServiceClient,
args: wasm_bindgen::JsValue,
) -> Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue> {
let args: CheckAccountGroupPermission = serde_wasm_bindgen::from_value(args)?;
let value =
client.client.call(args).await.map_err(|error| {
match serde_wasm_bindgen::to_value(&error) {
Ok(value) => value,
Err(error) => error.into(),
}
})?;
serde_wasm_bindgen::to_value(&value).map_err(Into::into)
} error:
and if we switch 'em: #[specta::specta]
#[wasm_bindgen::prelude::wasm_bindgen]
pub async fn create_account(
client: &__wasm::AccountServiceClient,
args: wasm_bindgen::JsValue,
) -> Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue> {
let args: CheckAccountGroupPermission = serde_wasm_bindgen::from_value(args)?;
let value =
client.client.call(args).await.map_err(|error| {
match serde_wasm_bindgen::to_value(&error) {
Ok(value) => value,
Err(error) => error.into(),
}
})?;
serde_wasm_bindgen::to_value(&value).map_err(Into::into)
} error:
|
Okay so found and fixed a couple of things. Using and then given the input: #[wasm_bindgen::prelude::wasm_bindgen]
#[specta]
pub fn testing() {} Rust gives Specta the tokens:
For this case, we can't really work out the types without reimplementing a bunch of the While if you switch around the macros: #[specta]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn testing() {} gives Specta the tokens:
and this was just broken due to a bug in Specta's macros parsing of paths (it tried to cast it to an ident). You could transform your code to the following and it should start working. I have fixed this on #[specta]
#[wasm_bindgen]
pub fn demo() {} Hopefully that helps! |
Utilizing "typescript_custom_section" (https://rustwasm.github.io/docs/wasm-bindgen/reference/attributes/on-rust-exports/typescript_custom_section.html) we could emit type bindings directly.
This seems to be non-trivial though, as it requires a const string.
(btw sorry for all these issues, I am just very excited about this amazing project and its potential)
The text was updated successfully, but these errors were encountered: