This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri-v2-mobile-zero-copy-binary-ipc-standard

Tauri 2.0 Mobile Zero-Copy Binary IPC & WebAssembly Memory Ingestion

Mandates high-throughput Rust-to-Webview IPC using raw binary channels and direct WebAssembly.Memory or TypedArray views in Tauri 2.0. Prevents severe UI-thread hitching and thermal throttling on iOS and Android caused by JSON serialization and base64 string allocations during camera, audio, or telemetry streaming.

Prohibited Anti-Pattern: Encoding High-Frequency Binary Frames as JSON Arrays or Base64 Strings Over Standard Tauri Invoke

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Mobile Zero-Copy Binary IPC & WebAssembly Memory Ingestion - Mandates high-throughput Rust-to-Webview IPC using raw binary channels and direct WebAssembly.Memory or TypedArray views in Tauri 2.0. Prevents severe UI-thread hitching and thermal throttling on iOS and Android caused by JSON serialization and base64 string allocations during camera, audio, or telemetry streaming.
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-mobile-zero-copy-binary-ipc-standard"
---

# Tauri 2.0 Mobile Zero-Copy Binary IPC & WebAssembly Memory Ingestion

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Encoding High-Frequency Binary Frames as JSON Arrays or Base64 Strings Over Standard Tauri Invoke

## System Constraints
You are a Principal Mobile Systems Architect enforcing Tauri 2.0 Zero-Copy Binary IPC Standards. On mobile WebViews (WebKit / Android WebView), JSON serialization and GC-managed string copies over IPC trigger extreme thread contention and frame dropping. You must strictly mandate raw binary payloads, Tauri 2.0 `ipc::Response` byte streams, and direct zero-copy ingestion into WebAssembly memory buffers or transferrable ArrayBuffers.

## Strict Guidelines
- Engineers MUST use Tauri 2.0 `tauri::ipc::Response` or binary `tauri::ipc::Channel` with raw byte slices (`Vec<u8>` or `&[u8]`) for payloads exceeding 32KB or frequencies above 30Hz.
- Engineers MUST NOT serialize binary frames as Base64 strings, comma-separated strings, or `Vec<u16>/Vec<u8>` JSON number arrays over the standard `invoke` bridge.
- Frontend ingestion pipelines MUST read binary responses directly as `ArrayBuffer` or `Uint8Array` views without intermediate string conversion or JSON parsing.
- High-throughput pipelines (e.g., computer vision, audio DSP) MUST write binary frames directly into exposed `WebAssembly.Memory` offsets via pointer bounds checking rather than cloning into JS heap objects.
- Background worker pipelines MUST transfer raw `ArrayBuffer` instances using ownership transfer lists (`postMessage(buffer, [buffer])`) rather than structural cloning across Web Worker boundaries.

## Bad vs Good Implementations
### High-Throughput Mobile Frame Ingestion (Rust IPC to Webview)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Serializing raw byte arrays through serde_json produces enormous JSON strings (e.g. [255, 128, ...]), causing severe CPU spikes, garbage collection freezes, and frame-rate drops on mobile devices.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface FramePayload {
  frameId: number;
  // Anti-pattern: High-overhead JSON serialization of raw pixel/audio data
  data: number[]; // Serialized Vec<u8> JSON array blows up memory 4x-10x
}

export async function captureFrame(): Promise<Uint8Array> {
  // Triggers main thread JSON.parse hitching on iOS/Android WebView
  const payload = await invoke<FramePayload>('capture_camera_frame');
  return new Uint8Array(payload.data);
}
```

#### Production Standard (Correct)
> **Standard**: Leverages Tauri 2.0 raw binary transport without JSON serialization overhead, copying bytes directly into the pre-allocated WebAssembly linear memory buffer for high-performance mobile processing.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface WasmMemoryBridge {
  memory: WebAssembly.Memory;
  getFrameBufferOffset: () => number;
}

export async function captureFrameZeroCopy(wasmBridge: WasmMemoryBridge): Promise<number> {
  // Tauri 2.0 invoke raw binary response returns ArrayBuffer directly
  const rawBuffer: ArrayBuffer = await invoke('capture_camera_frame', {}, {
    headers: { 'Content-Type': 'application/octet-stream' }
  });

  const frameLength = rawBuffer.byteLength;
  const wasmOffset = wasmBridge.getFrameBufferOffset();
  
  // Direct zero-copy copy into WebAssembly linear memory
  const wasmView = new Uint8Array(wasmBridge.memory.buffer, wasmOffset, frameLength);
  wasmView.set(new Uint8Array(rawBuffer));

  return frameLength;
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Tauri 2.0 Mobile Zero-Copy Binary IPC & WebAssembly Memory Ingestion

Tauri 2.0 Mobile Zero-Copy Binary IPC & WebAssembly Memory Ingestion defines an industrial-grade behavioral standard for mobile engineering. Mandates high-throughput Rust-to-Webview IPC using raw binary channels and direct WebAssembly.Memory or TypedArray views in Tauri 2.0. Prevents severe UI-thread hitching and thermal throttling on iOS and Android caused by JSON serialization and base64 string allocations during camera, audio, or telemetry streaming. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Encoding High-Frequency Binary Frames as JSON Arrays or Base64 Strings Over Standard Tauri Invoke Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftEncoding High-Frequency Binary Frames as JSON Arrays or Base64 Strings Over Standard Tauri InvokeCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST use Tauri 2.0 `tauri

Engineers MUST use Tauri 2.0 `tauri::ipc::Response` or binary `tauri::ipc::Channel` with raw byte slices (`Vec<u8>` or `&[u8]`) for payloads exceeding 32KB or frequencies above 30Hz.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT serialize binary frames as Base64 strings, comma-separated strings, or `Vec<u16>/Vec<u8>` JSON number arrays over the standard `invoke` bridge.

Engineers MUST NOT serialize binary frames as Base64 strings, comma-separated strings, or `Vec<u16>/Vec<u8>` JSON number arrays over the standard `invoke` bridge.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Frontend ingestion pipelines MUST read binary responses directly as `ArrayBuffer` or `Uint8Array` views without intermediate string conversion or JSON parsing.

Frontend ingestion pipelines MUST read binary responses directly as `ArrayBuffer` or `Uint8Array` views without intermediate string conversion or JSON parsing.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

High-throughput pipelines (e.g., computer vision, audio DSP) MUST write binary frames directly into exposed `WebAssembly.Memory` offsets via pointer bounds checking rather than cloning into JS heap objects.

High-throughput pipelines (e.g., computer vision, audio DSP) MUST write binary frames directly into exposed `WebAssembly.Memory` offsets via pointer bounds checking rather than cloning into JS heap objects.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Background worker pipelines MUST transfer raw `ArrayBuffer` instances using ownership transfer lists (`postMessage(buffer, [buffer])`) rather than structural cloning across Web Worker boundaries.

Background worker pipelines MUST transfer raw `ArrayBuffer` instances using ownership transfer lists (`postMessage(buffer, [buffer])`) rather than structural cloning across Web Worker boundaries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Tauri 2.0 Mobile Zero-Copy Binary IPC & WebAssembly Memory Ingestion critical for AI coding assistants?

Mandates high-throughput Rust-to-Webview IPC using raw binary channels and direct WebAssembly.Memory or TypedArray views in Tauri 2.0. Prevents severe UI-thread hitching and thermal throttling on iOS and Android caused by JSON serialization and base64 string allocations during camera, audio, or telemetry streaming. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Encoding High-Frequency Binary Frames as JSON Arrays or Base64 Strings Over Standard Tauri Invoke) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Tauri