expression
Pass Unicode strings across the JavaScript boundary
JavaScript strings use UTF-16 code units; the binding converts to Rust UTF-8. Rust str::len measures bytes rather than scalar values or grapheme clusters. This example measures the Rust representation, not the JavaScript length. Unpaired JS surrogates cannot round-trip as ordinary Rust strings unchanged. Expected result (NOT RUN): label_bytes("سلام") returns 8; label_bytes("😀") returns 4. Common mistake: Assuming JavaScript .length equals Rust str::len. Static Rust source module for the accompanying Cargo lab; not a standalone executable or ByteMind exercise.
Formal Syntax & Structure
rust syntaxrust
#[wasm_bindgen] pub fn label_bytes(text: &str) -> usizeWorking Example
Example Snippetrust
use wasm_bindgen::prelude::*;#[wasm_bindgen]pub fn label_bytes(text: &str) -> usize { text.len() }