Skip to main content

Crate surrealism_types

Crate surrealism_types 

Source
Expand description

§surrealism-types

A language-agnostic serialization framework for WebAssembly (WASM) guest-host communication.

§Overview

This crate provides the core types and traits for transferring data across WASM boundaries in a way that can be implemented by any language that compiles to WebAssembly. It defines:

§Feature Flags

  • host: Enables async traits for host-side (runtime) implementations. Without this flag, all operations are synchronous, suitable for WASM guest modules.

§Dual-Mode Architecture

The crate supports both synchronous (guest) and asynchronous (host) operations:

  • Guest mode (default): Synchronous traits for WASM module code
  • Host mode (host feature): Async traits for runtime/Wasmtime code

This allows the same types to work efficiently on both sides of the WASM boundary.

§Example

use surrealism_types::{Serializable, Transfer, MemoryController};

// Guest side: Transfer a string to host
fn send_string(s: String, controller: &mut dyn MemoryController) -> u32 {
    let ptr = s.transfer(controller).unwrap();
    *ptr
}

// Guest side: Receive a string from host
fn receive_string(ptr: u32, controller: &mut dyn MemoryController) -> String {
    String::receive(ptr.into(), controller).unwrap()
}

Modules§

arg
Wrapper type for function arguments that implement surrealdb_types::SurrealValue. Wrapper type for serializable function arguments.
args
Traits for marshalling function arguments to and from surrealdb_types::Value vectors. Function argument marshalling for SurrealDB values.
controller
Memory management abstractions for WASM linear memory allocation and deallocation. Memory management abstractions for WASM linear memory.
err
Error handling utilities for adding context to errors. Error handling utilities for adding context to errors.
serialize
Core serialization traits and implementations for the binary wire format. Core serialization traits and binary wire format implementations.
transfer
Memory transfer traits for moving data across WASM boundaries. Memory transfer traits for moving data across WASM boundaries.