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::Utf8holds every well-formed value andRepr::Wtf16only ill-formed ones (at least one unpaired surrogate). The derivedPartialEq/Hashare only sound under this invariant: a well-formed value smuggled intoWtf16would compare unequal to itsUtf8twin. The representation is private so the invariant holds by construction; match onJsString::as_refto branch on well-formedness.
Enums§
- JsString
Ref - Borrowed view of a
JsStringfor callers that need to branch on well-formedness.