#rune #data #character #type #fn #structure #characters


User-perceived characters related types and data structures

11 releases

0.1.10 May 23, 2022
0.1.9 May 23, 2022
0.1.6 Sep 19, 2021
0.1.5 Aug 15, 2021

#349 in Rust patterns

Download history 9/week @ 2022-11-20 2/week @ 2022-11-27 4/week @ 2022-12-04 18/week @ 2022-12-11 4/week @ 2022-12-18 7/week @ 2022-12-25 1/week @ 2023-01-01 5/week @ 2023-01-08 5/week @ 2023-01-15 7/week @ 2023-01-22 12/week @ 2023-01-29 16/week @ 2023-02-05 31/week @ 2023-02-12 27/week @ 2023-02-19 2/week @ 2023-02-26 4/week @ 2023-03-05

64 downloads per month
Used in runestr-pancjkv



rune, RuneStr and RuneString

User-perceived characters type rune and its related types and data structures.


use runestr::{rune, RuneString};

fn main() {
    let runestr = RuneString::from_str_lossy("\u{0041}\u{0341}\u{304B}\u{3099}\u{9508}");
    assert_eq!(3, runestr.runes().count());


Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


User-perceived characters related types and data structures.

The rune type represents a user-perceived character. It roughly corresponds to a Unicode grapheme cluster but with some nice properties. Runes that consists of two or more chars are automatically registered on a per-thread basis. This also means that runes are neither Send nor Sync.

The RuneStr type, also called a "rune string slice", is a primitive rune-based string type. It is usally seen in its borrowed form, &RuneStr.

Rune string slices are encoded in a special encoding called FSS-UTF, which is a super-set of UTF-8 encoding. This allows all runes be encoded.

The RuneString type, is a growable rune-based string type.

Rune definition

Our rune definition is based on the extended grapheme cluster defined within UAX-29. On top of this, we will convert all the CJK Compatibility Ideographs to their equivalent IVS form, and then convert the text to NFC form. We also apply a few specfic "lossy conversion" rules when necessary. The rules are defined below, and their goal to make each of the rune "standalone", that is, when two runes are put next to one each other, they won't automatically merge together into one larger rune.

Rules for lossy conversion within a rune

  • An orphan abstract character CR (U+000D) is converted into CR LF sequence.
  • If a hangul-syllable doesn't contain CHOSEONG or JUNGSEONG jamos, corresponding filter (U+115F, U+1160) will be automatically added.
  • An orphan Regional Indicator (U+1F1E6..U+1F1FF) abstract character is automatically appended another copy to make it no longer orphan.
  • An Extended Pictographic sequence that ends with the abstract character ZWJ (U+200D) with an optional sequence of continuing characters before it, will get another extra ZWJ (U+200D) abstract character to prevent it merging with next rune to form a larger Extended Pictographic sequence.
  • If no base character is provided, a space (U+0020) character is inserted.


~52K SLoC