Feature: Generate Typescript functions for Rust commands
Goal: Atomatically generate Typescript functions for Rust commands in Typescript environment Why: Use Typescript with type checking for Rust commands rather than `invoke('some string', somedata)` How: Assume these Rust commands are available ```rust #[tauri::command] async fn my_first_custom_command(message: String) -> Result<String, String> { Ok("simple type command".into()) } #[derive(serde::Serialize)] struct CustomResponse { message: String, other_val: usize, } #[derive(serde::Deserialize)] struct CustomRequest { message: String, request: usize, } #[tauri::command] async fn my_second_custom_command(req: CustomRequest, hello: String) -> Result<CustomResponse, String> { Ok(CustomResponse { message: "custom response".into(), other_val: 42, }) } ``` Using Typescript, we can create functions that conform to the Rust commands: ```typescript import tauriapi from "@tauri-apps/api"; const { invoke } = tauriapi.tauri; function my_first_custom_command(message: String): Promise<String> { return invoke('my_first_custom_command', { message }) } type CustomRequest = { message: String; request: Number; } type CustomResponse = { message: String; other_val: Number; } function my_second_custom_command(req: CustomRequest, hello: String): Promise<CustomResponse>{ return invoke('my_second_custom_command', {req, hello}) } export { my_first_custom_command, my_second_custom_command } ``` Now we can call `my_first_custom_command` and `my
Posted by nganhkhoa on Apr 16, 2021, 10:22 AM
Tags
Related issues
- struct's lifetime requirements can be bypassed via covariant field assignment
- Proposal to Reorganize the Moderation Team and Review Moderation Policies
- Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
- proposal: container/...: generic collection types
- Better Custom Endpoint BYOK
- A concrete policy for backward compatibility until Godot 5.0
Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments
github (Other)
struct's lifetime requirements can be bypassed via covariant field assignment
Proposal to Reorganize the Moderation Team and Review Moderation Policies
Progressive FPS degradation appears to be related to dota2.com — blocking the domain prevents the performance loss
proposal: container/...: generic collection types
Better Custom Endpoint BYOK
A concrete policy for backward compatibility until Godot 5.0
New MTP models not supported
Tracking: 429 / Capacity Issues
Feature: Generate Typescript functions for Rust commands
Goal: Atomatically generate Typescript functions for Rust commands in Typescript environment Why: Use Typescript with type checking for Rust commands rather than `invoke('some string', somedata)` How: Assume these Rust commands are available ```rust #[tauri::command] async fn my_first_custom_command(message: String) -> Result<String, String> { Ok("simple type command".into()) } #[derive(serde::Serialize)] struct CustomResponse { message: String, other_val: usize, } #[derive(serde::Deserialize)] struct CustomRequest { message: String, request: usize, } #[tauri::command] async fn my_second_custom_command(req: CustomRequest, hello: String) -> Result<CustomResponse, String> { Ok(CustomResponse { message: "custom response".into(), other_val: 42, }) } ``` Using Typescript, we can create functions that conform to the Rust commands: ```typescript import tauriapi from "@tauri-apps/api"; const { invoke } = tauriapi.tauri; function my_first_custom_command(message: String): Promise<String> { return invoke('my_first_custom_command', { message }) } type CustomRequest = { message: String; request: Number; } type CustomResponse = { message: String; other_val: Number; } function my_second_custom_command(req: CustomRequest, hello: String): Promise<CustomResponse>{ return invoke('my_second_custom_command', {req, hello}) } export { my_first_custom_command, my_second_custom_command } ``` Now we can call `my_first_custom_command` and `my
Comments (0)
No comments yet. Start the discussion.