Skip to main content

Module js_string

Module js_string 

Source
Expand description

A JavaScript string value. JS strings are sequences of UTF-16 code units with no validity requirement, so a value can contain unpaired surrogate halves that Rust’s String cannot represent. JsString keeps the common valid case as UTF-8 and falls back to code units only when the value is ill-formed, so the compiler computes on true program values instead of replacement characters or escape hatches.

Wire format: the babel bridge transports lone surrogates as __SURROGATE_XXXX__ markers (see sanitizeJsonSurrogates in bridge.ts), because serde_json can neither parse nor emit a lone \uXXXX escape. Serde for JsString decodes and re-emits that marker form, which keeps the JS side of the bridge unchanged.

Structs§

JsString
Invariant: Repr::Utf8 holds every well-formed value and Repr::Wtf16 only ill-formed ones (at least one unpaired surrogate). The derived PartialEq/Hash are only sound under this invariant: a well-formed value smuggled into Wtf16 would compare unequal to its Utf8 twin. The representation is private so the invariant holds by construction; match on JsString::as_ref to branch on well-formedness.

Enums§

JsStringRef
Borrowed view of a JsString for callers that need to branch on well-formedness.