Module token

Module token 

Source
Expand description

Provides low-level, granular, token-based JSON string processing.

This module offers the most fundamental building blocks for both escaping and unescaping. It provides iterators, UnescapeTokens and EscapeTokens, that walk a byte/string slice and yield tokens. This approach is highly flexible and composable, allowing consumers to handle the data in a zero-copy, streaming fashion for literal (non-processed) parts.

§Unescaping

The UnescapeTokens iterator yields UnescapedTokens, separating literal byte slices from single unescaped chars. This ensures that in the case of an error (e.g., an invalid escape sequence), all preceding valid literal parts have already been successfully yielded.

§Escaping

The EscapeTokens iterator yields EscapedTokens, separating literal string slices from the &'static str representation of an escaped character. This allows for efficient, allocation-free iteration over a string to produce its JSON-escaped form.

Structs§

DisplayUnescapeTokens
A wrapper struct for implementing fmt::Display on an UnescapeTokens iterator.
DisplayUnescapedToken
Helper struct for safely displaying an DisplayUnescapedToken.
EscapeTokens
An iterator over a string that yields EscapedTokens.
UnescapeTokens
An iterator over a byte slice that yields UnescapedTokens.

Enums§

EscapedToken
A token representing a piece of an escaped JSON string.
UnescapedToken
A token representing a piece of an unescaped JSON string.

Functions§

escape_str
Creates an iterator that yields tokens of an escaped JSON string.
unescape
Creates an iterator that yields tokens of an unescaped JSON string.