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

Filter

Filter example for WASM

Code

use space_lib::space;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct Package {
    name: String,
    amount: u64,
}

#[space]
fn main(input: Vec<Package>) -> Vec<Package> {
    input
        .into_iter()
        .filter(|it| it.name.contains("Space") && it.amount > 10)
        .collect()
}

Node Definition

{
  "type": "WASM",
  "data": {
    "node_id": "filter",
    "version": "0.1",
    "display_name": "Filter",
    "description": "Takes list of packages and filters them",
    "width": 150,
    "height": 175,
    "backgroundColor": "#ffd9b3"
  },
  "targets": [
    {
      "name": "packages",
      "type_bounds": [
        {
          "array": {
            "object": {
              "name": "string",
              "amount": "u64"
            }
          }
        }
      ],
      "required": true,
      "defaultValue": "",
      "tooltip": "",
      "passthrough": false
    }
  ],
  "sources": [
    {
      "name": "output",
      "type": {
        "array": {
          "object": {
            "name": "string",
            "amount": "u64"
          }
        }
      },
      "defaultValue": "",
      "tooltip": ""
    }
  ]
}
PreviousRectangleNextRegex

Last updated 2 years ago

Was this helpful?