rfc9839 0.3.0

Implementation of the RFC 9839 specification
Documentation
  • Coverage
  • 100%
    22 out of 22 items documented19 out of 19 items with examples
  • Size
  • Source code size: 39.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 295.73 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ryanfowler/rfc9839-rs
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ryanfowler

rfc9839

Crates.io Docs.rs License

Validation of RFC 9839 Unicode subsets in Rust.

RFC 9839 defines three nested subsets of Unicode characters for use in text protocols:

  • Unicode Scalars – all code points except UTF-16 surrogates. Every Rust char is already a scalar value; checks are included for completeness and for raw byte validation.
  • XML Characters{ TAB, LF, CR } ∪ [0x20–0xD7FF] ∪ [0xE000–0xFFFD] ∪ [0x10000–0x10FFFF]. This is the XML “Char” production with surrogates, C0 controls except TAB/LF/CR, and U+FFFE/U+FFFF excluded.
  • Unicode Assignables – all scalar values that are not legacy controls, surrogates, or standardized noncharacters, including currently unassigned code points.

Features

  • String-level APIs: is_unicode_scalar, is_xml_chars, is_unicode_assignable at the crate root and in rfc9839::str
  • Byte-level APIs: rfc9839::bytes::{is_unicode_scalar, is_xml_chars, is_unicode_assignable}
  • Character-level APIs: rfc9839::chars::{is_unicode_scalar, is_xml_char, is_unicode_assignable}
  • Backwards-compatible aliases: is_unicode_scalar_bytes, is_xml_chars_bytes, is_unicode_assignable_bytes, is_unicode_scalar_char, is_xml_char, is_unicode_assignable_char
  • ASCII fast-path: tight loops for XML and Assignable ASCII data, falling back to chars() only after the first non-ASCII byte
  • Zero allocations, no lookup tables

Example

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