silk.json.text.
Decode the text of a JSON string token, including its escapes, into owned bytes.
When to use#
Use JsonText.decode in a Deserialize implementation, after JsonScanner returned a
JsonToken.String. Pass the raw bytes of the token, its offset, and its escaped flag. The
result is valid UTF-8, so String.fromBytesUnchecked can take it without a check.
Import as JsonText with import silk.json.text { JsonText }.
Public declarations: 1.
JsonText#
pub struct JsonTextThe owner type of the string decoding operations. It has no fields and is never constructed.
Implementation JsonText#
impl JsonTextAssociated function copy#
pub effect fn copy(raw: &[u8]) -> Bytes ! OutOfMemoryError ? &mut AllocatorReturns an owned copy of raw.
Gotchas#
raw must be bytes that the scanner already checked as valid UTF-8 text with no escapes.
Errors#
OutOfMemoryErrorif theAllocatorcannot supply the copy.
Associated function decode#
pub effect fn decode(raw: &[u8], offset: usize, escaped: bool)
-> Bytes ! JsonError | OutOfMemoryError ? &mut AllocatorReturns the text of the quoted string token raw, with escapes such as \n and \u00e9
decoded.
When to use#
Use it in a Deserialize implementation, after JsonScanner returned a JsonToken.String.
Pass the raw bytes of the token, its offset, and its escaped flag.
Details#
The result is valid UTF-8, so String.fromBytesUnchecked can take it without a check. raw
includes the quotes. offset is the position of the token in the document, for errors.
If escaped is false, the text is copied without a scan for escapes.
Errors#
JsonErrorwith reasonUnterminatedStringifrawis shorter than two bytes, orInvalidEscapefor an escape that is not valid.OutOfMemoryErrorif theAllocatorcannot supply the text.
Category: Data formats.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.