forked from madonoharu/tsify
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added vector support for using tsify to export types and auto-generate bindings for vectors of structs.
- Loading branch information
Showing
12 changed files
with
494 additions
and
665 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
* @param {Point} point | ||
*/ | ||
export function consume(point: Point): void; | ||
/** | ||
* @returns {Point} | ||
*/ | ||
export function into_js(): Point; | ||
/** | ||
* @param {(Point)[]} points | ||
*/ | ||
export function consume_vector(points: (Point)[]): void; | ||
/** | ||
* @returns {(Point)[]} | ||
*/ | ||
export function vector_into_js(): (Point)[]; | ||
export interface Point { | ||
x: number; | ||
y: number; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "test4" | ||
publish = false | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
tsify-next = { path = "../..", version = "*" } | ||
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
|
||
[dev-dependencies] | ||
wasm-bindgen-test = "0.3" | ||
|
||
[lib] | ||
path = "entry_point.rs" | ||
crate-type = ["cdylib"] | ||
|
||
[build-dependencies] | ||
wasm-bindgen-cli = "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use tsify_next::Tsify; | ||
use wasm_bindgen::prelude::*; | ||
|
||
#[derive(Tsify, Serialize, Deserialize)] | ||
#[tsify(into_wasm_abi, from_wasm_abi)] | ||
pub struct Point { | ||
x: i32, | ||
y: i32, | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn consume(point: Point) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn into_js() -> Point { | ||
Point { x: 0, y: 0 } | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn consume_vector(points: Vec<Point>) {} | ||
|
||
#[wasm_bindgen] | ||
pub fn vector_into_js() -> Vec<Point> { | ||
vec![ | ||
Point { x: 1, y: 6 }, | ||
Point { x: 2, y: 5 }, | ||
Point { x: 3, y: 4 }, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.