Rectangle
Rectangle example for WASM
Code
use space_lib::space;
use serde::{Serialize, Deserialize};
#[derive(Deserialize)]
struct Input {
width: u64,
height: u64,
}
#[derive(Serialize)]
struct Output {
area: u64,
perimeter: u64,
}
#[space]
fn main(input: Input) -> Output {
Output {
area: input.width * input.height,
perimeter: 2 * (input.width + input.height),
}
}
Node Definition
{
"type": "WASM",
"data": {
"node_id": "rectangle",
"version": "0.1",
"display_name": "Rectangle",
"description": "Calculates rectangle from width and height",
"width": 150,
"height": 225,
"backgroundColor": "#ffd9b3"
},
"targets": [
{
"name": "width",
"type_bounds": [
"u64"
],
"required": true,
"defaultValue": "",
"tooltip": "",
"passthrough": false
},
{
"name": "height",
"type_bounds": [
"u64"
],
"required": true,
"defaultValue": "",
"tooltip": "",
"passthrough": false
}
],
"sources": [
{
"name": "output",
"type": {
"object": {
"area": "u64",
"perimeter": "u64"
}
},
"defaultValue": "",
"tooltip": ""
}
]
}
Last updated
Was this helpful?