Space Operator
  • Welcome
  • Visual Builder
    • Flows
      • API Key & POST Request
      • WebSocket
        • Signature Requests
      • Nested Flows
      • Learn Solana
      • Add flows to your websites
      • Iterate with Localhost
    • Nodes
      • Web Assembly Nodes
        • space-cli
        • space-lib
        • Examples in Rust
          • Rectangle
          • Filter
          • Regex
        • Uploading WASM binary via UI
      • Native Nodes
        • Code Template
        • Node Definition
        • ValueSet
        • Submitting Native Nodes
        • Tracing
      • Mock Nodes
      • JS Node
      • API Input Node
  • Self-hosting
    • Docker Compose
    • Serving HTTPS
    • Lightsail Instance
    • Export data to your instance
  • FAQ
    • Servers
  • References
    • Flows
    • Flow Deployment
Powered by GitBook
On this page
  • Code
  • Node Definition

Was this helpful?

  1. Visual Builder
  2. Nodes
  3. Web Assembly Nodes
  4. Examples in Rust

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": ""
    }
  ]
}
PreviousExamples in RustNextFilter

Last updated 2 years ago

Was this helpful?