Expand description
§RFC 9839 Unicode Subset Validators
This crate provides fast, zero-allocation checks to validate whether individual characters, strings, or raw byte slices conform to the subsets defined in RFC 9839:
- Unicode Scalars — all code points except the UTF-16 surrogate range.
In Rust, all
charvalues are scalars by construction, but functions are included for completeness and defensive validation of&str/ byte data. - XML Characters — the “Char” production from XML:
{TAB, LF, CR} ∪ [0x20–0xD7FF] ∪ [0xE000–0xFFFD] ∪ [0x10000–0x10FFFF]. Excludes surrogates, C0 controls except TAB/LF/CR, and U+FFFE/U+FFFF. - Unicode Assignables — all scalar values that are not legacy controls, surrogates, or standardized noncharacters, including currently unassigned code points.
§Features
- String-level APIs (
is_*) are available at the crate root and instr. XML/Assignable validation uses an ASCII fast-path where validation is required: scan raw bytes first, and only fall back tochars()after the first non-ASCII byte. - Byte-level APIs are available in
bytesfor validating raw UTF-8 input. Scalar validation only needs UTF-8 validation; XML/Assignable checks decode the tail once and returnfalseon invalid UTF-8. - Character-level APIs are available in
charsand implemented asconst fnwith simple range tests. - Backwards-compatible aliases such as
is_xml_chars_bytesandis_xml_charremain available at the crate root. - Zero allocations, no heap lookups, no tables.
§Examples
use rfc9839::{bytes, chars};
// Scalars (always true for safe Rust strings)
assert!(rfc9839::is_unicode_scalar("hello 🌍"));
// XML Characters
assert!(rfc9839::is_xml_chars("ok\tline\n"));
assert!(!rfc9839::is_xml_chars("\u{0000}")); // NUL is disallowed
// Byte and character APIs live in modules.
assert!(bytes::is_unicode_assignable("emoji 👍".as_bytes()));
assert!(!chars::is_unicode_assignable('\u{007F}')); // DEL is excluded§Performance
All string/byte checks run in O(n). ASCII data is validated in a tight loop;
non-ASCII triggers a one-time chars() traversal or UTF-8 decode. These
functions are designed for high-throughput pipelines, parsers, and
validators.
Modules§
- bytes
- Byte-level validators for UTF-8 encoded data.
- chars
- Character-level validators.
- str
- String-level validators for
&str.
Functions§
- is_
unicode_ assignable - Returns
trueif all characters insare Unicode Assignables. - is_
unicode_ assignable_ bytes - Returns
trueifbytesare all valid Unicode Assignables. - is_
unicode_ assignable_ char - Returns
trueifcis a Unicode Assignable character per RFC 9839. - is_
unicode_ scalar - Returns
trueif all code points insare Unicode scalar values. - is_
unicode_ scalar_ bytes - Returns
trueifbytesare valid Unicode scalar values. - is_
unicode_ scalar_ char - Returns
trueifcis a Unicode scalar value per RFC 9839. - is_
xml_ char - Returns
trueifcis an XML Character as defined in RFC 9839. - is_
xml_ chars - Returns
trueif all characters insare XML Characters. - is_
xml_ chars_ bytes - Returns
trueifbytesare all valid XML Characters.